hanifekaptan commited on
Commit
cd14a0c
·
verified ·
1 Parent(s): 2aa00e2

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +95 -0
  2. corona.csv +113 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import bar_chart_race as bcr
4
+
5
+ def user_guide_show():
6
+ st.write("""
7
+ This application creates racing charts consisting of bar graphs by calculating the cumulative totals of the data based on the time column.
8
+
9
+ Points to consider:
10
+ 1. The dataset must include a date column.
11
+ 2. It is recommended that the date column be in a structured format.
12
+ 3. Accepted formats for the date column:
13
+ -> ISO 8601 Format
14
+ -> US Date Format
15
+ -> European Date Format
16
+ -> Unix Timestamp
17
+ -> Abbreviated Month Names
18
+ 4. It is recommended that the dataset be pre-processed (missing values may hinder achieving the desired outcome).
19
+ 5. Below is an example of a dataset:
20
+ """)
21
+ data = pd.read_csv('corona.csv')
22
+ st.dataframe(data)
23
+
24
+
25
+ def create_graph(data: pd.DataFrame, title):
26
+ data['date'] = pd.to_datetime(data['date'])
27
+ data = data.set_index('date')
28
+ cumulative = data.cumsum()
29
+
30
+ try:
31
+ bcr.bar_chart_race(cumulative,
32
+ n_bars = min(10, len(data.columns)),
33
+ filename = 'racing_graph.mp4',
34
+ figsize = (10, 8),
35
+ interpolate_period=True,
36
+ cmap='tab20',
37
+ period_length = 500,
38
+ steps_per_period = min(5, max(1, int(len(data) / 500))),
39
+ period_label = False,
40
+ title = title)
41
+
42
+ except Exception as e:
43
+ st.error(f"Racing graph could not be generated: {e}")
44
+
45
+
46
+ def download_graph():
47
+ try:
48
+ with open('racing_graph.mp4', 'rb') as f:
49
+ st.download_button(
50
+ label="Download",
51
+ data=f,
52
+ file_name='racing_graph.mp4',
53
+ mime='video/mp4'
54
+ )
55
+
56
+ except Exception as e:
57
+ st.error(f"Racing graph could not be downloaded: {e}")
58
+
59
+
60
+ st.title("RACING GRAPHS")
61
+
62
+ user_guide = st.button("User Guide")
63
+
64
+ if user_guide:
65
+ user_guide_show()
66
+
67
+ title = st.text_input("Enter the title of the graph")
68
+
69
+ dataset = st.file_uploader("Upload the dataset", type= ["csv", "xlsx", "json", "txt", "pkl"])
70
+
71
+ generate = st.button("Generate")
72
+ if generate and dataset is not None:
73
+ try:
74
+ name = str(dataset.name)
75
+ if name.endswith(".csv"):
76
+ data = pd.read_csv(dataset)
77
+ elif name.endswith(".xlsx"):
78
+ data = pd.read_excel(dataset)
79
+ elif name.endswith(".json"):
80
+ data = pd.read_json(dataset)
81
+ elif name.endswith(".txt"):
82
+ data = pd.read_csv(dataset)
83
+ elif name.endswith(".pkl"):
84
+ data = pd.read_pickle(dataset)
85
+ else:
86
+ st.error("Unsupported file type.")
87
+ data = None
88
+
89
+ except Exception as e:
90
+ st.error(f"An error occurred while uploading the file: {e}")
91
+
92
+
93
+ create_graph(data, title)
94
+
95
+ download_graph()
corona.csv ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ date,US,Spain,Italy,Germany,Russia,Brazil,France,United Kingdom,Turkey,Iran
2
+ 1-22-2020,1,0,0,0,0,0,0,0,0,0
3
+ 1-23-2020,0,0,0,0,0,0,0,0,0,0
4
+ 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2-25-2020,1,4,96,1,0,0,9,0,0,38
37
+ 2-26-2020,6,7,135,11,0,1,5,0,0,96
38
+ 2-27-2020,1,2,249,20,0,0,20,2,0,113
39
+ 2-28-2020,3,17,238,2,0,0,19,5,0,175
40
+ 2-29-2020,9,13,248,31,0,1,44,3,0,264
41
+ 3-1-2020,6,39,608,51,0,0,30,13,0,448
42
+ 3-2-2020,29,36,426,29,1,0,62,4,0,651
43
+ 3-3-2020,21,46,504,37,0,0,14,11,0,846
44
+ 3-4-2020,35,58,731,66,0,2,84,35,0,862
45
+ 3-5-2020,69,38,948,220,1,0,94,30,0,793
46
+ 3-6-2020,47,143,936,189,9,9,279,49,0,1425
47
+ 3-7-2020,143,133,1349,130,0,0,305,54,0,1853
48
+ 3-8-2020,120,180,1658,241,5,7,185,67,0,1257
49
+ 3-9-2020,66,413,1996,138,0,5,83,49,0,898
50
+ 3-10-2020,383,629,1145,281,3,6,589,67,0,1272
51
+ 3-11-2020,330,752,2830,459,0,7,514,75,1,1249
52
+ 3-12-2020,391,1,0,170,8,14,0,2,0,1150
53
+ 3-13-2020,524,3043,6031,1622,17,99,1419,344,4,1374
54
+ 3-14-2020,557,1545,4199,912,19,0,827,360,0,1462
55
+ 3-15-2020,787,1501,4327,1212,4,11,36,16,1,2953
56
+ 3-16-2020,1164,2210,3996,1504,27,39,2209,431,12,1182
57
+ 3-17-2020,1823,2495,4063,1992,24,123,1032,457,30,2112
58
+ 3-18-2020,1481,2305,5766,3112,33,53,1409,730,51,1339
59
+ 3-19-2020,6074,4286,6164,3017,54,252,1941,117,96,1516
60
+ 3-20-2020,5643,3141,6613,4618,54,177,1995,1334,168,2421
61
+ 3-21-2020,6449,5833,8982,2435,56,232,1817,1109,316,1979
62
+ 3-22-2020,7822,4241,7163,2703,65,535,4087,713,587,1453
63
+ 3-23-2020,10767,6907,5390,4212,71,387,4066,1055,300,1538
64
+ 3-24-2020,10285,6465,7294,6941,63,335,3783,1660,350,2866
65
+ 3-25-2020,12363,12042,6929,4690,172,320,3866,1662,602,3061
66
+ 3-26-2020,18788,10637,7914,8802,191,453,5364,2366,1212,3378
67
+ 3-27-2020,18548,11048,7417,7993,204,447,4902,3218,2102,3746
68
+ 3-28-2020,20477,11288,8297,8738,232,506,5040,2861,1748,3761
69
+ 3-29-2020,21726,10120,6619,5230,289,377,4399,2683,1873,3736
70
+ 3-30-2020,24673,10830,6452,9191,305,460,5619,3067,1704,4823
71
+ 3-31-2020,28896,11194,5999,7653,564,1187,9708,3419,2831,3996
72
+ 4-1-2020,27654,12506,6627,8809,516,1158,7344,5055,2301,3943
73
+ 4-2-2020,32327,13004,6859,10849,822,1292,4659,4973,2617,4237
74
+ 4-3-2020,33776,11754,6831,8668,651,1047,7982,5247,2924,4073
75
+ 4-4-2020,39837,11424,6724,6927,643,1390,6789,4556,3391,4519
76
+ 4-5-2020,32468,10033,5660,6471,682,811,3208,6619,3464,2634
77
+ 4-6-2020,33167,8086,5257,3477,1007,1109,5843,4472,3507,6910
78
+ 4-7-2020,35283,8742,5198,11876,1253,1995,7332,4746,4224,5025
79
+ 4-8-2020,35408,11838,6477,16185,1266,2269,6367,6581,4468,4891
80
+ 4-9-2020,37962,9801,6793,11250,1590,2099,7611,5516,4448,4248
81
+ 4-10-2020,39213,9188,6506,5656,1901,1653,7141,10115,5126,5250
82
+ 4-11-2020,34350,8720,7392,6193,1929,1156,5229,6143,5775,8444
83
+ 4-12-2020,32379,7689,6200,6132,2456,1564,28216,6022,5367,3721
84
+ 4-13-2020,37584,6151,4943,6390,2755,1343,4788,4787,4702,3817
85
+ 4-14-2020,33724,5519,5269,5287,3020,4909,6520,6342,5011,3818
86
+ 4-15-2020,35485,9104,4207,8304,3708,14242,6808,5529,5271,3410
87
+ 4-16-2020,35942,11855,6383,7593,3800,2293,15100,5702,6341,3994
88
+ 4-17-2020,38540,6578,6631,10113,4397,3474,4378,6579,6021,3423
89
+ 4-18-2020,41128,928,6173,4338,5292,3189,2207,6683,5726,3370
90
+ 4-19-2020,33301,9918,5608,4569,6342,10208,5915,6379,5627,2466
91
+ 4-20-2020,29223,5165,4532,5657,4467,2214,3760,5259,6251,3635
92
+ 4-21-2020,32841,6325,5986,5097,6120,3351,5078,5680,6218,3077
93
+ 4-22-2020,32974,8047,6750,6803,5840,5170,-168,5358,4759,3436
94
+ 4-23-2020,33968,8410,6143,6677,5287,5959,4270,5366,5245,2850
95
+ 4-24-2020,56833,-6562,6363,8555,6586,5462,3444,6419,6477,3017
96
+ 4-25-2020,36351,6646,5394,1631,6714,7139,3162,5823,6812,2804
97
+ 4-26-2020,35373,4681,4392,3556,6944,4997,1127,4892,6014,2677
98
+ 4-27-2020,28186,4665,3768,3638,6824,5653,4790,4681,6877,2363
99
+ 4-28-2020,31033,3282,4790,4242,7594,7671,4830,4919,7502,2689
100
+ 4-29-2020,34723,8996,4720,4780,7776,8468,-741,4932,8256,2505
101
+ 4-30-2020,64771,3889,6850,4726,8533,9798,2293,6718,7554,2366
102
+ 5-1-2020,46052,1781,4538,4581,9630,7525,960,6978,7194,2284
103
+ 5-2-2020,41871,7121,4039,3066,11469,8145,1830,5441,6512,1899
104
+ 5-3-2020,31584,2702,3303,2351,12317,7070,766,4662,6623,2095
105
+ 5-4-2020,30603,3150,2641,2715,12113,9934,1553,4288,6693,2254
106
+ 5-5-2020,28729,3646,3663,3255,11967,9812,2803,5119,7010,2482
107
+ 5-6-2020,27490,3756,9827,6237,12107,14955,5049,6773,7234,2870
108
+ 5-7-2020,35025,3844,4706,3185,13795,13744,1984,6193,6816,2710
109
+ 5-8-2020,32381,4276,4317,1276,13602,15895,2228,5306,5308,2704
110
+ 5-9-2020,40777,3704,5285,2375,16229,12194,916,4246,4680,2804
111
+ 5-10-2020,24076,3129,3122,1675,13490,10377,561,4193,4800,2513
112
+ 5-11-2020,36341,4182,2324,2006,17245,9852,1224,4107,4258,3007
113
+ 5-12-2020,20723,2611,4026,2255,14717,14641,2213,4045,4866,2464
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ bar-chart-race==0.1.0
2
+ pandas
3
+ streamlit