euler314 commited on
Commit
9a12078
·
verified ·
1 Parent(s): 57005a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -1
app.py CHANGED
@@ -130,7 +130,51 @@ class TyphoonAnalyzer:
130
  today = datetime.now()
131
  return (today.day == 1 or today.day == 15 or
132
  today.day == (today.replace(day=1, month=today.month%12+1) - timedelta(days=1)).day)
133
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  def update_oni_data(self):
135
  if not self.should_update_oni():
136
  return
 
130
  today = datetime.now()
131
  return (today.day == 1 or today.day == 15 or
132
  today.day == (today.replace(day=1, month=today.month%12+1) - timedelta(days=1)).day)
133
+ def convert_typhoondata(self, input_file, output_file):
134
+ """Convert IBTrACS data to processed format"""
135
+ print(f"Converting typhoon data from {input_file} to {output_file}")
136
+ with open(input_file, 'r') as infile:
137
+ # Skip the header lines
138
+ next(infile)
139
+ next(infile)
140
+
141
+ reader = csv.reader(infile)
142
+ sid_data = defaultdict(list)
143
+
144
+ for row in reader:
145
+ if not row: # Skip blank lines
146
+ continue
147
+
148
+ sid = row[0]
149
+ iso_time = row[6]
150
+ sid_data[sid].append((row, iso_time))
151
+
152
+ with open(output_file, 'w', newline='') as outfile:
153
+ fieldnames = ['SID', 'ISO_TIME', 'LAT', 'LON', 'SEASON', 'NAME',
154
+ 'WMO_WIND', 'WMO_PRES', 'USA_WIND', 'USA_PRES',
155
+ 'START_DATE', 'END_DATE']
156
+ writer = csv.DictWriter(outfile, fieldnames=fieldnames)
157
+ writer.writeheader()
158
+
159
+ for sid, data in sid_data.items():
160
+ start_date = min(data, key=lambda x: x[1])[1]
161
+ end_date = max(data, key=lambda x: x[1])[1]
162
+
163
+ for row, iso_time in data:
164
+ writer.writerow({
165
+ 'SID': row[0],
166
+ 'ISO_TIME': iso_time,
167
+ 'LAT': row[8],
168
+ 'LON': row[9],
169
+ 'SEASON': row[1],
170
+ 'NAME': row[5],
171
+ 'WMO_WIND': row[10].strip() or ' ',
172
+ 'WMO_PRES': row[11].strip() or ' ',
173
+ 'USA_WIND': row[23].strip() or ' ',
174
+ 'USA_PRES': row[24].strip() or ' ',
175
+ 'START_DATE': start_date,
176
+ 'END_DATE': end_date
177
+ })
178
  def update_oni_data(self):
179
  if not self.should_update_oni():
180
  return