smomtaz commited on
Commit
c56d2c9
·
verified ·
1 Parent(s): 7d9d072

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +95 -3
server.py CHANGED
@@ -26,6 +26,92 @@ QUESTION_TO_SHEET = {
26
  "Where are trips starting and ending within Napa County?": "OD1",
27
  }
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  def create_server(app_dir):
30
  def server(input, output, session):
31
 
@@ -149,11 +235,17 @@ def create_server(app_dir):
149
 
150
  try:
151
  # Load the sheet
152
- df = pd.read_excel(EXCEL_FILE, sheet_name=sheet_name, skiprows=0, header=None)
 
 
 
 
 
153
  # Extract title from the first row
154
- title = df.iloc[0, 0] if not df.empty else "No title found"
 
155
  # Skip the first two rows and use the third row as headers
156
- data = pd.read_excel(EXCEL_FILE, sheet_name=sheet_name, skiprows=2)
157
  return {"title": title, "data": data}
158
  #except Exception as e:
159
  # return {"title": f"Error: {str(e)}", "data": pd.DataFrame()}
 
26
  "Where are trips starting and ending within Napa County?": "OD1",
27
  }
28
 
29
+ tables_json = {
30
+ "TTyp1": {
31
+ "Trip Type": [
32
+ "Intra-Napa County Trips",
33
+ "Trips into Napa County",
34
+ "Trips out of Napa County",
35
+ "Napa County Pass-Through Trips",
36
+ "Total Trips Interacting with Napa County"
37
+ ],
38
+ "Trips": [238000, 52000, 51000, 12000, 353000],
39
+ "Previous TBS Trips": [238000, 48000, 47000, 12000, 345000],
40
+ "Percent": ["67%", "15%", "15%", "3%", "100%"],
41
+ "Previous TBS Percentage": ["68%", "14%", "14%", "3%", "100%"]
42
+ },
43
+ "GWTTyp1": {
44
+ "Napa County Gateway": [
45
+ "SR 29 at Napa/Solano County Line - Northbound",
46
+ "SR 29 at Napa/Solano County Line - Southbound",
47
+ "SR 12 at Napa/Solano County Line - Westbound",
48
+ "SR 12 at Napa/Solano County Line - Eastbound",
49
+ "SR 29 at Napa/Lake County Line - Southbound",
50
+ "SR 29 at Napa/Lake County Line - Northbound",
51
+ "SR 128 at Napa/Sonoma County Line - Eastbound",
52
+ "SR 128 at Napa/Sonoma County Line - Westbound",
53
+ "SR 12 at Napa/Sonoma County Line - Eastbound",
54
+ "SR 12 at Napa/Sonoma County Line - Westbound",
55
+ "SR 128 at Napa/Solano County Line - Westbound",
56
+ "SR 128 at Napa/Solano County Line - Eastbound",
57
+ "SMR at Napa/Sonoma County Line - Westbound",
58
+ "SMR at Napa/Sonoma County Line - Eastbound",
59
+ "All Napa County Gateway Trips"
60
+ ],
61
+ "Total Trips": [
62
+ 23000, 24000, 24000, 22000, 4000, 4000, 1000, 1000, 16000, 15000,
63
+ 600, 600, 400, 300, 124000
64
+ ],
65
+ "Napa County Pass-Through Trips": [
66
+ "4%", "6%", "16%", "16%", "56%", "48%", "22%", "26%", "29%", "29%",
67
+ "17%", "11%", "3%", "7%", "10%"
68
+ ],
69
+ "Trips into Napa County": [
70
+ "82%", "2%", "83%", "0%", "27%", "0%", "70%", "0%", "70%", "70%",
71
+ "69%", "69%", "33%", "50%", "42%"
72
+ ],
73
+ "Trips out of Napa County": [
74
+ "1%", "76%", "0%", "84%", "6%", "27%", "0%", "70%", "0%", "0%",
75
+ "6%", "6%", "60%", "0%", "41%"
76
+ ]
77
+ },
78
+ "TT1": {
79
+ "Location": [
80
+ "Vallejo", "Fairfield", "Santa Rosa", "Vacaville", "City of Sonoma", "Total"
81
+ ],
82
+ "Calistoga": [16, 35, 149, 9, 4, 213],
83
+ "Angwin": [48, 0, 7, 0, 4, 59],
84
+ "Saint Helena": [67, 207, 189, 126, 66, 655],
85
+ "Yountville": [69, 75, 26, 107, 105, 382],
86
+ "Napa": [5125, 4384, 3131, 2005, 1290, 15935],
87
+ "American Canyon": [6534, 1449, 326, 412, 154, 8875],
88
+ "Unincorporated": [1374, 1271, 1350, 762, 303, 5060],
89
+ "Total": [13233, 7421, 5178, 3421, 1926, 31179]
90
+ },
91
+ "OD1": {
92
+ "Location": [
93
+ "Vallejo", "Fairfield", "Santa Rosa", "Vacaville", "City of Sonoma", "Total"
94
+ ],
95
+ "Calistoga": [16, 35, 149, 9, 4, 213],
96
+ "Angwin": [48, 0, 7, 0, 4, 59],
97
+ "Saint Helena": [67, 207, 189, 126, 66, 655],
98
+ "Yountville": [69, 75, 26, 107, 105, 382],
99
+ "Napa": [5125, 4384, 3131, 2005, 1290, 15935],
100
+ "American Canyon": [6534, 1449, 326, 412, 154, 8875],
101
+ "Unincorporated": [1374, 1271, 1350, 762, 303, 5060],
102
+ "Total": [13233, 7421, 5178, 3421, 1926, 31179]
103
+ }
104
+ }
105
+
106
+ tables_title_json = = {
107
+ "TTyp1": ["Table 4.1: Weekday All-Day Trip Types"],
108
+ "GWTTyp1": ["Table 4.2: Weekday All-Day Gateway Trip Types"],
109
+ "TT1": ["Table 4.3: Weekday All-Day Top Five Generators of Inbound Trips"],
110
+ "OD1": ["Table 4.4: Weekday All-Day Origins and Destinations by City"]
111
+ }
112
+
113
+
114
+
115
  def create_server(app_dir):
116
  def server(input, output, session):
117
 
 
235
 
236
  try:
237
  # Load the sheet
238
+ #df = pd.read_excel(EXCEL_FILE, sheet_name=sheet_name, skiprows=0, header=None)
239
+ # Parse JSON string
240
+ df = json.loads(tables_json)
241
+ data_title = json.loads(tables_title_json)
242
+ # Convert each nested dictionary to a DataFrame
243
+ data = pd.DataFrame(data[sheet_name])
244
  # Extract title from the first row
245
+ #title = df.iloc[0, 0] if not df.empty else "No title found"
246
+ title = data_title[sheet_name]
247
  # Skip the first two rows and use the third row as headers
248
+ #data = pd.read_excel(EXCEL_FILE, sheet_name=sheet_name, skiprows=2)
249
  return {"title": title, "data": data}
250
  #except Exception as e:
251
  # return {"title": f"Error: {str(e)}", "data": pd.DataFrame()}