@@ -44,6 +44,9 @@ def to_csv(data, product, product_subtype, location_type=None, output_dir=None):
4444 elif product_subtype == 'summary' :
4545 df = format_adaptation_summary (data )
4646
47+ elif product_subtype == 'summary_detail' :
48+ df = format_adaptation_summary_detail (data )
49+
4750 else :
4851 raise NotImplementedError
4952
@@ -83,6 +86,9 @@ def to_csv(data, product, product_subtype, location_type=None, output_dir=None):
8386 else :
8487 df = format_historic_summary (data )
8588
89+ elif product_subtype == 'summary_event' :
90+ df = format_historic_summary_event (data )
91+
8692 else :
8793 raise NotImplementedError
8894
@@ -136,8 +142,7 @@ def to_csv(data, product, product_subtype, location_type=None, output_dir=None):
136142 raise NotImplementedError
137143
138144 # Export CSVs
139- df .fillna (pd .NA , inplace = True )
140- df .to_csv (output_dir + '/' + file_name , index = False )
145+ df .fillna (pd .NA ).astype (str ).to_csv (output_dir + '/' + file_name , index = False )
141146 logging .info ("CSV generated to '{}'." .format (output_dir + '/' + file_name ))
142147
143148
@@ -157,7 +162,7 @@ def format_adaptation_detail(data):
157162
158163
159164def format_adaptation_summary (data ):
160- """Reformat the list of data to Adaptation Summary format
165+ """Reformat the list of data to Adaptation Summary Detail format
161166
162167 Args:
163168 data (list): A list of FSF object
@@ -166,9 +171,28 @@ def format_adaptation_summary(data):
166171 """
167172 df = pd .DataFrame ([vars (o ) for o in data ]).explode ('adaptation' ).reset_index (drop = True )
168173 df ['fsid' ] = df ['fsid' ].apply (str )
174+ df ['adaptation' ] = df ['adaptation' ].astype ('Int64' ).apply (str )
169175 return df [['fsid' , 'adaptation' , 'properties' ]]
170176
171177
178+ def format_adaptation_summary_detail (data ):
179+ """Reformat the list of data to Adaptation Summary format
180+
181+ Args:
182+ data (list): A list of FSF object
183+ Returns:
184+ A pandas formatted DataFrame
185+ """
186+
187+ summary = format_adaptation_summary (data [0 ])
188+ detail = format_adaptation_detail (data [1 ])
189+
190+ df = pd .merge (summary , detail , left_on = 'adaptation' , right_on = 'adaptationId' , how = 'left' )\
191+ .drop ('adaptationId' , axis = 1 )
192+
193+ return df
194+
195+
172196def format_probability_chance (data ):
173197 """Reformat the list of data to Probability Chance format
174198
@@ -245,9 +269,6 @@ def format_probability_count_summary(data):
245269 Returns:
246270 A pandas formatted DataFrame
247271 """
248- # listed_data = [{'fsid': attr.fsid, 'location': [{'state': attr.state}, {'city': attr.city}, {'zcta': attr.zcta},
249- # {'neighborhood': attr.neighborhood}, {'tract': attr.tract},
250- # {'county': attr.county}, {'cd': attr.cd}]} for attr in data]
251272 listed_data = [{'fsid' : attr .fsid , 'location' : [{'location' : 'state' , 'data' : attr .state },
252273 {'location' : 'city' , 'data' : attr .city },
253274 {'location' : 'zcta' , 'data' : attr .zcta },
@@ -462,6 +483,21 @@ def format_historic_summary(data):
462483 return df [['fsid' , 'eventId' , 'name' , 'type' , 'bin' , 'count' ]]
463484
464485
486+ def format_historic_summary_event (data ):
487+ """Reformat the list of data to Historic Summary Event format
488+
489+ Args:
490+ data (list): A list of FSF object
491+ Returns:
492+ A pandas formatted DataFrame
493+ """
494+
495+ summary = format_historic_summary (data [0 ])
496+ event = format_historic_event (data [1 ])
497+
498+ return pd .merge (summary , event , on = 'eventId' , how = 'left' )
499+
500+
465501def format_location_detail_property (data ):
466502 """Reformat the list of data to Location Detail format for property
467503
0 commit comments