def calculate(places, year, type, fname): '''Function calculates year extremes statistics''' colspan = 15 # Make data list with station and year statistics yearextremes = list() for place in places: console.log(f'Process extremes {place.place} for the year {year}...', True) ok, data = daydata.read(place) # Get data stations if ok: days = daydata.period(data, f'{year}****') # Get the days in period if days.size != 0: # Skip station if not yearextremes.append(Stats(place, days, year)) # Create yearstats object console.log(f'\nPreparing output: {type}', True) # Make path if it is a html or txt file dir = utils.mk_path(cfg.dir_yearextremes, type) path = utils.mk_path(dir, f'{fname}.{type}') fio.mk_dir(dir) # Sort on TG # dayextremes = sort( dayextremes, '+' ) # Make output title, main, footer = '', '', '' # Maak content op basis van type uitvoer html of text # Maak titel table_title = f'Extremes ' if type in ['txt', 'cmd']: pass elif type == 'html': title += f''' <table id="stats"> <thead> <tr> <th colspan="{colspan}"> {icon.weather_all()} {table_title} {icon.wave_square()} {year} {icon.cal_period()} </th> </tr> <tr> <th title="copyright data_notification"> </th> <th> place {icon.home(size='fa-sm')} </th> <th> province {icon.flag(size='fa-sm')} </th> <th> period {icon.cal_period(size='fa-sm')} </th> <th> year {icon.cal_period(size='fa-sm')} </th> <th title="Highest maximum temperature"> tx {icon.arrow_up(size='fa-sm')} </th> <th title="Lowest maximum temperature"> tx {icon.arrow_down(size='fa-sm')} </th> <th title="Highest mean temperature"> tg {icon.arrow_up(size='fa-sm')} </th> <th title="Lowest mean temperature"> tg {icon.arrow_down(size='fa-sm')} </th> <th title="Highest minimum temperature"> tn {icon.arrow_up(size='fa-sm')} </th> <th title="Lowest minimum temperature"> tn {icon.arrow_down(size='fa-sm')} </th> <th title="Highest ground minimum temperature"> tn10 {icon.arrow_up(size='fa-sm')} </th> <th title="Lowest ground minimum temperature"> tn10 {icon.arrow_down(size='fa-sm')} </th> <th title="Maximum sunshine"> sq {icon.arrow_up(size='fa-sm')} </th> <th title="Maximum rain"> rh {icon.arrow_up(size='fa-sm')} </th> </tr> </thead> <tbody> ''' # Walkthrough all cities for s in yearextremes: console.log(f'Make {type} output for: {s.station.place}', True) tx_max = fix.ent(s.tx_max, 'TX') tx_min = fix.ent(s.tx_min, 'TX') tg_max = fix.ent(s.tg_max, 'TG') tg_min = fix.ent(s.tg_min, 'TG') tn_max = fix.ent(s.tn_max, 'TN') tn_min = fix.ent(s.tn_min, 'TN') tn10_max = fix.ent(s.tn10_max, 'T10N') tn10_min = fix.ent(s.tn10_min, 'T10N') sq_max = fix.ent(s.sq_max, 'SQ') rh_max = fix.ent(s.rh_max, 'RH') if type == 'html': period_txt = f'{utils.ymd_to_txt(s.p_start)} - {utils.ymd_to_txt(s.p_end)}' main += f''' <tr> <td title="{s.station.data_notification.lower()}"> {icon.copy_light(size='fa-xs')} </td> <td> <span class="val"> {s.station.place} </span> </td> <td> <span class="val"> {s.station.province} </span> </td> <td title="{period_txt}"> <span class="val"> {s.period} </span> </td> <td title="The year is {year}"> <span class="val"> {year} </span> </td> <td> <span class="val"> {tx_max} </span> {html.table_days( s.tx_max_sort, 'TX', 'TXH' )} </td> <td> <span class="val"> {tx_min} </span> {html.table_days(np.flip(s.tx_max_sort, axis=0), 'TX', 'TXH')} </td> <td> <span class="val"> {tg_max} </span> {html.table_days( s.tg_max_sort, 'TG' )} </td> <td> <span class="val"> {tg_min} </span> {html.table_days(np.flip(s.tg_max_sort, axis=0), 'TG' )} </td> <td> <span class="val"> {tn_max} </span> {html.table_days(s.tn_max_sort, 'TN', 'TNH')} </td> <td> <span class="val"> {tn_min} </span> {html.table_days(np.flip(s.tn_max_sort, axis=0), 'TN', 'TNH')} </td> <td> <span class="val"> {tn10_max} </span> {html.table_days(s.tn10_max_sort, 'T10N', 'T10NH')} </td> <td> <span class="val"> {tn10_min} </span> {html.table_days(np.flip(s.tn10_max_sort, axis=0), 'T10N', 'T10NH')} </td> <td> <span class="val"> {sq_max} </span> {html.table_days(s.sq_max_sort, 'SQ')} </td> <td> <span class="val"> {rh_max} </span> {html.table_days(s.rh_max_sort, 'RH')} </td> </tr> ''' if type in ['txt', 'cmd']: footer += cfg.knmi_dayvalues_notification if type == 'html': footer += f''' </tbody> <tfoot> <tr> <td colspan="{colspan}"> {utils.now_created_notification()} </td> </tr> </tfoot> </table> ''' path_to_root = './../../' # Path to html root console.log('\nWrite/print results... ', True) # Write to file or console output = f'{title}\n{main}\n{footer}' if type == 'cmd': console.log(output, True) elif type == 'html': page = html.Template() page.title = table_title page.main = output page.strip = True page.path_to_root = path_to_root page.file_path = path # Styling page.css_files = [ f'{path_to_root}yearextremes/css/default.css', f'{path_to_root}static/css/table-statistics.css', f'{path_to_root}yearextremes/css/yearextremes.css' ] # Scripts page.script_files = [ f'{path_to_root}yearextremes/js/yearextremes.js', f'{path_to_root}static/js/sort-col.js', f'{path_to_root}static/js/default.js' ] page.save() elif type == 'txt': fio.save(path, output) # Schrijf naar bestand return path
def calculate(stations, period, name=False, type='html'): '''Function calculates all statistics''' colspan = 33 # Make data list with station and summerstatistics allstats = list() for station in stations: console.log(f'Calculate statistics: {station.place}', True) ok, data = daydata.read(station) # Get data stations if ok: days = daydata.period(data, period) # Get days of period if days.size != 0: # Skip station allstats.append(Stats(station, days)) # Create summerstats object console.log(f'\nPreparing output: {type}', True) # Update name if there is none yet if not name: name = utils.mk_name('all-statistics', period) # Make path if it is a html or txt file dir = utils.mk_path(cfg.dir_allstats, type) path = utils.mk_path(dir, f'{name}.{type}') fio.mk_dir(dir) # Sort on TG allstats = sort(allstats, '+') # Make output title, main, footer = '', '', '' # Maak content op basis van type uitvoer html of text # Maak titel table_title = 'All statistics ' if type in ['txt', 'cmd']: s = ' ' title += f'{table_title} {period}\n' title += f'PLACE{s:15} ' title += f'PROVINCE{s:7} ' title += f'PERIOD{s:11} ' title += f'TG{s:5} ' title += f'WARMTH ' title += 'TX MAX ' title += 'TG MAX ' title += 'TN MAX ' title += 'TX≥20 ' title += 'TX≥25 ' title += 'TX≥30 ' title += 'TX≥35 ' title += 'TX≥40 ' title += 'TG≥20 ' title += 'TG≥18 ' title += 'TN≥20 ' title += 'ZON≥10 ' title += 'ZON{s:6} ' title += 'REGEN≥10 ' title += 'REGEN\n' if type == 'html': title += f''' <table id="stats"> <thead> <tr> <th colspan="{colspan}"> {icon.weather_all()} {table_title} {icon.wave_square()} {period} {icon.cal_period()} </th> </tr> <tr> <th title="copyright data_notification"> </th> <th> place {icon.home(size='fa-sm')} </th> <th> province {icon.flag(size='fa-sm')} </th> <th> period {icon.cal_period(size='fa-sm')} </th> <th title="Average temperature"> tg {icon.temp_half(size='fa-sm')} </th> <th title="Highest maximum temperature"> tx {icon.arrow_up(size='fa-sm')} </th> <th title="Highest average temperature"> tg {icon.arrow_up(size='fa-sm')} </th> <th title="Highest minimum temperature"> tn {icon.arrow_up(size='fa-sm')} </th> <th title="Lowest maximum temperature"> tx {icon.arrow_down(size='fa-sm')} </th> <th title="Lowest average temperature "> tg {icon.arrow_down(size='fa-sm')} </th> <th title="Lowest minumum temperature"> tn {icon.arrow_down(size='fa-sm')} </th> <th title="Total hours of sunshine"> {icon.sun(size='fa-sm')} </th> <th title="Total rain mm"> {icon.shower_heavy(size='fa-sm')} </th> <th title="Heat index tg greater than 18 degrees celsius"> heat {icon.fire(size='fa-sm')} </th> <th title="Warm days"> tx{icon.gte(size='fa-xs')}20 </th> <th title="Summer days"> tx{icon.gte(size='fa-xs')}25 </th> <th title="Tropical days"> tx{icon.gte(size='fa-xs')}30 </th> <th title="High tropical days"> tx{icon.gte(size='fa-xs')}35 </th> <th title="High tropical days"> tx{icon.gte(size='fa-xs')}40 </th> <th title="Warm days on average"> tg{icon.gte(size='fa-xs')}18 </th> <th title="Tropical nights"> tn{icon.gte(size='fa-xs')}20 </th> <th title="Days with more than 10hour of sun"> {icon.sun(size='fa-xs')}{icon.gte(size='fa-xs')}10h </th> <th title="Days with more than 10 mm of rain"> {icon.shower_heavy(size='fa-xs')}{icon.gte(size='fa-xs')}10mm </th> <th title="Hellmann"> hmann {icon.icicles(size='fa-sm')}</th> <th title="IJnsen"> ijnsen {icon.icicles(size='fa-sm')}</th> <th title="Frost sum"> fsum {icon.icicles(size='fa-sm')}</th> <th title="Days with maximum temperature below 0 degrees celsius"> tx{icon.lt(size='fa-xs')}0 </th> <th title="Days with average temperature below 0 degrees celsius"> tg{icon.lt(size='fa-xs')}0 </th> <th title="Days with minimum temperature below 0 degrees celsius"> tn{icon.lt(size='fa-xs')}0 </th> <th title="Days with minimum temperature lower than -5 degrees celsius"> tn{icon.lt(size='fa-xs')}−5 </th> <th title="Days with minimum temperature lower than -10 degrees celsius"> tn{icon.lt(size='fa-xs')}−10 </th> <th title="Days with minimum temperature lower than -15 degrees celsius"> tn{icon.lt(size='fa-xs')}−15 </th> <th title="Days with minimum temperature lower than -20 degrees celsius"> tn{icon.lt(size='fa-xs')}−20 </th> </tr> </thead> <tbody> ''' # Walkthrough all cities for s in allstats: console.log(f'Make {type} output for: {s.station.place}', True) heat_ndx = fix.ent(s.heat_ndx, 'heat_ndx') tg_ave = fix.ent(s.tg_ave, 'tg') tx_max = fix.ent(s.tx_max, 'tx') tg_max = fix.ent(s.tg_max, 'tg') tn_max = fix.ent(s.tn_max, 'tn') tx_min = fix.ent(s.tx_min, 'tx') tg_min = fix.ent(s.tg_min, 'tg') tn_min = fix.ent(s.tn_min, 'tn') hellmann = fix.ent(s.hellmann, 'hellmann') ijnsen = fix.ent(s.ijnsen, 'ijnsen') f_sum = fix.ent(s.frost_sum, 'frost_sum') sq_sum = fix.ent(s.sq_sum, 'SQ') rh_sum = fix.ent(s.rh_sum, 'RH') if type in ['txt', 'cmd']: main += f'{s.station.place:<21} ' main += f'{s.station.province:<16} ' main += f'{s.station.period:<18} ' main += f'{tg_ave:<7} ' main += f'{heat_ndx:<7} ' main += f'{tx_max:<7} ' main += f'{tg_max:<7} ' main += f'{tn_max:<7} ' main += f'{tx_gte_20:^6} ' main += f'{tx_gte_25:^6} ' main += f'{tx_gte_30:^6} ' main += f'{tx_gte_35:^6} ' main += f'{tg_gte_20:^6} ' main += f'{tg_gte_18:^6} ' main += f'{tn_gte_20:^6} ' main += f'{sq_gte_10:^7} ' main += f'{sq_tot:<10} ' main += f'{rh_gte_10:^9} ' main += f'{rh_tot:<11} ' if type == 'html': period_txt = f'{utils.ymd_to_txt(s.p_start)} - {utils.ymd_to_txt(s.p_end)}' main += f''' <tr> <td title="{s.station.data_notification.lower()}"> {icon.copy_light(size='fa-xs')} </td> <td> <span class="val"> {s.station.place} </span> </td> <td> <span class="val"> {s.station.province} </span> </td> <td title="{period_txt}"> <span class="val"> {s.period} </span> </td> <td> <span class="val"> {tg_ave} </span> </td> <td> <span class="val"> {tx_max} </span> {html.table_days( s.tx_max_sort, 'TX', 'TXH' )} </td> <td> <span class="val"> {tg_max} </span> {html.table_days( s.tg_max_sort, 'TG' )} </td> <td> <span class="val"> {tn_max} </span> {html.table_days( s.tn_max_sort, 'TN', 'TNH' )} </td> <td> <span class="val"> {tx_min} </span> {html.table_days( s.tx_min_sort, 'TX', 'TXH' )} </td> <td> <span class="val"> {tg_min} </span> {html.table_days( s.tg_min_sort, 'TG' )} </td> <td> <span class="val"> {tn_min} </span> {html.table_days( s.tn_min_sort, 'TN', 'TNH' )} </td> <td> <span class="val"> {sq_sum} </span> {html.table_days( s.sq_sort , 'SQ' )} </td> <td> <span class="val"> {rh_sum} </span> {html.table_days( s.rh_sort, 'RH' )} </td> <td> <span class="val"> {heat_ndx} </span> {html.table_heat_ndx( s.days_heat_ndx, 'TG' )} </td> <td> <span class="val"> {np.size(s.days_tx_gte_20, axis=0)} </span> {html.table_days_count(s.days_tx_gte_20, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size(s.days_tx_gte_25, axis=0)} </span> {html.table_days_count(s.days_tx_gte_25, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size(s.days_tx_gte_30, axis=0)} </span> {html.table_days_count(s.days_tx_gte_30, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size(s.days_tx_gte_35, axis=0)} </span> {html.table_days_count(s.days_tx_gte_35, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size(s.days_tx_gte_40, axis=0)} </span> {html.table_days_count(s.days_tx_gte_40, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size(s.days_tg_gte_18, axis=0)} </span> {html.table_days_count(s.days_tg_gte_18, 'TG' )} </td> <td> <span class="val"> {np.size(s.days_tn_gte_20, axis=0)} </span> {html.table_days_count(s.days_tn_gte_20, 'TG' )} </td> <td> <span class="val"> {np.size(s.days_sq_gte_10, axis=0)} </span> {html.table_days_count(s.days_sq_gte_10, 'SQ' )} </td> <td> <span class="val"> {np.size(s.days_rh_gte_10, axis=0)} </span> {html.table_days_count(s.days_rh_gte_10, 'RH' )} </td> <td> <span class="val"> {hellmann} </span> {html.table_hellmann( s.days_hellmann )} </td> <td> <span class="val"> {ijnsen} </span> </td> <td> <span class="val"> {f_sum} </span> {html.table_frost_sum( s.frost_sum_data )} </td> <td> <span class="val"> {np.size( s.days_tx_lt_0, axis=0 )} </span> {html.table_days_count( s.days_tx_lt_0, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size( s.days_tg_lt_0, axis=0 )} </span> {html.table_days_count( s.days_tg_lt_0, 'TG' )} </td> <td> <span class="val"> {np.size( s.days_tn_lt_0, axis=0 )} </span> {html.table_days_count( s.days_tn_lt_0, 'TN', 'TNH' )} </td> <td> <span class="val"> {np.size( s.days_tn_lt__5, axis=0 )} </span> {html.table_days_count( s.days_tn_lt__5, 'TN', 'TNH' )} </td> <td> <span class="val"> {np.size( s.days_tn_lt__10, axis=0 )} </span> {html.table_days_count( s.days_tn_lt__10, 'TN', 'TNH' )} </td> <td> <span class="val"> {np.size( s.days_tn_lt__15, axis=0 )} </span> {html.table_days_count( s.days_tn_lt__15, 'TN', 'TNH' )} </td> <td> <span class="val"> {np.size( s.days_tn_lt__20, axis=0 )} </span> {html.table_days_count( s.days_tn_lt__20, 'TN', 'TNH' )} </td> </tr> ''' if type in ['txt', 'cmd']: footer += cfg.knmi_dayvalues_notification if type == 'html': footer += f''' </tbody> <tfoot> <tr> <td colspan="{colspan}"> {utils.now_created_notification()} </td> </tr> </tfoot> </table> ''' path_to_root = './../../' # Path to html root console.log('\nWrite/print results... ', True) # Write to file or console output = f'{title}\n{main}\n{footer}' if type == 'cmd': console.log(output, True) elif type == 'html': page = html.Template() page.title = table_title page.main = output page.strip = True page.path_to_root = path_to_root page.file_path = path # Styling page.css_files = [ f'{path_to_root}allstats/css/default.css', f'{path_to_root}static/css/table-statistics.css', f'{path_to_root}allstats/css/allstats.css' ] # Scripts page.script_files = [ f'{path_to_root}allstats/js/allstats.js', f'{path_to_root}static/js/sort-col.js', f'{path_to_root}static/js/default.js' ] page.save() elif type == 'txt': fio.save(path, output) # Schrijf naar bestand return path
def calculate(places, period, query, type, fname): data = process( places, period, query ) # All days for the terms given # Make path if it is a html or txt file dir = utils.mk_path(cfg.dir_search4days, type) path = utils.mk_path(dir, f'{fname}.{type}') fio.mk_dir(dir) if type =='html': title = f'Days {query}' # Proces data in html table colspan = 30 html = f''' <table id="stats"> <thead> <tr> <th colspan="{colspan}"> {icon.weather_all()} {title} {icon.wave_square()} {period} {icon.cal_period()} </th> </tr> <tr> <th title="copyright data_notification"> </th> <th> place {icon.home(size='fa-sm')}</th> <th> state {icon.flag(size='fa-sm')}</th> <th> periode {icon.cal_period(size='fa-sm')}</th> <th> day {icon.cal_day(size='fa-sm')}</th> <th> TX {icon.temp_full(size='fa-sm')}</th> <th> TG {icon.temp_half(size='fa-sm')}</th> <th> TN {icon.temp_empty(size='fa-sm')}</th> <th> T10N {icon.temp_empty(size='fa-sm')}</th> <th> SQ {icon.sun(size='fa-sm')}</th> <th> SP {icon.sun(size='fa-sm')}</th> <th> RH {icon.shower_heavy(size='fa-sm')}</th> <th> RHX {icon.shower_heavy(size='fa-sm')} </th> <th> DR {icon.shower_heavy(size='fa-sm')}</th> <th> PG {icon.compress_alt(size='fa-sm')}</th> <th> PX {icon.compress_alt(size='fa-sm')}</th> <th> PN {icon.compress_alt(size='fa-sm')}</th> <th> UG {icon.drop_tint(size='fa-sm')}</th> <th> UX {icon.drop_tint(size='fa-sm')}</th> <th> UN {icon.drop_tint(size='fa-sm')}</th> <th> NG {icon.cloud(size='fa-sm')}</th> <th> DDVEC {icon.arrow_loc(size='fa-sm')}</th> <th> FHVEC {icon.wind(size='fa-sm')}</th> <th> FG {icon.wind(size='fa-sm')}</th> <th> FHX {icon.wind(size='fa-sm')}</th> <th> FHN {icon.wind(size='fa-sm')}</th> <th> FXX {icon.wind(size='fa-sm')}</th> <th> VVX {icon.eye(size='fa-sm')}</th> <th> VVN {icon.eye(size='fa-sm')}</th> <th> Q {icon.radiation(size='fa-sm')}</th> </tr> </thead> <tbody> ''' if len(data) > 0: for day in data: stn, ymd, ddvec, fhvec, fg, fhx, fhxh, fhn, fhnh, fxx, fxxh, tg, \ tn, tnh, tx, txh, t10n, t10nh, sq, sp, q, dr, rh, rhx, \ rhxh, pg, px, pxh, pn, pnh, vvn, vvnh, vvx, vvxh, ng, ug, \ ux, uxh, un, unh, ev24 = dayvalues.ents( day ) place = stations.from_wmo_to_name(stn) state = stations.from_wmo_to_province(stn) station = stations.from_wmo_to_station(stn) date = f'{day[daydata.YYYYMMDD]:.0f}' html += f''' <tr> <td title="{station.data_notification.lower()}"> {icon.copy_light(size='fa-xs')} </td> <td> <span class="val">{place}</span> </td> <td> <span class="val">{state}</span> </td> <td> <span class="val">{period}</span> </td> <td title="{utils.ymd_to_txt(date)}"> <span class="val">{date}</span> </td> <td> <span class="val">{tx}</span> <br> <small>{txh}</small> </td> <td> <span class="val">{tg}</span> </td> <td> <span class="val">{tn}</span> <br> <small>{tnh}</small> </td> <td> <span class="val">{t10n}</span> <br> <small>{t10nh}</small> </td> <td> <span class="val">{sq}</span> </td> <td> <span class="val">{sp}</span> </td> <td> <span class="val">{rh}</span> </td> <td> <span class="val">{rhx}</span> <br> <small>{rhxh}</small> </td> <td> <span class="val">{dr}</span> </td> <td> <span class="val">{pg}</span> </td> <td> <span class="val">{px}</span> <br> <small>{pxh}</small> </td> <td> <span class="val">{pn}</span> <br> <small>{pnh}</small> </td> <td> <span class="val">{ug}</span> </td> <td> <span class="val">{ux}</span> <br> <small>{uxh}</small> </td> <td> <span class="val">{un}</span> <br> <small>{unh}</small> </td> <td> <span class="val">{ng}</span> </td> <td> <span class="val">{ddvec}</span> </td> <td> <span class="val">{fhvec}</span> </td> <td> <span class="val">{fg}</span> </td> <td> <span class="val">{fhx}</span> <br> <small>{fhxh}</small> </td> <td> <span class="val">{fhn}</span> <br> <small>{fhnh}</small> </td> <td> <span class="val">{fxx}</span> <br> <small>{fxxh}</small> </td> <td> <span class="val">{vvx}</span> <br> <small>{vvxh}</small> </td> <td> <span class="val">{vvn}</span> <br> <small>{vvnh}</small> </td> <td> <span class="val">{q}</span> </td> </tr> ''' else: html += f''' <tr> <td colspan="{colspan}"> {tr.t("No days found")} </td> </tr> ''' html += f''' </tbody> <tfoot> <tr> <td colspan="{colspan}">{utils.now_created_notification()}</td> </tr> </tfoot> </table> ''' path_to_root = './../../' # Path to html root console.log('\nWrite/print results... ', True) # Write to html, screen, console page = vhtml.Template() page.title = title page.main = html page.strip = True page.path_to_root = path_to_root page.file_path = path # Styling page.css_files = [ f'{path_to_root}search4days/css/default.css', f'{path_to_root}static/css/table-statistics.css', f'{path_to_root}search4days/css/search4days.css' ] # Scripts page.script_files = [ f'{path_to_root}search4days/js/search4days.js', f'{path_to_root}static/js/sort-col.js', f'{path_to_root}static/js/default.js' ] page.save() elif type == 'text': # TODO: pass elif type == 'cmd': # TODO pass return path
def calculate(places, period, type, check=False, download=False): console.log(f'\nStart make dayvalues...\n', True) cnt_places = len(places) path = '' link = '' for place in places: console.log(f'Station: {place.wmo} {place.place}', True) if download: daydata.process_data( stations.from_wmo_to_station(place.wmo) ) console.log(' ') d1 = daydata.read_station_period(place, period)[1] dates = d1[:, daydata.YYYYMMDD] cnt_dates = len(dates) # Base directory dir = utils.mk_path(config.dir_dayvalues, type) fio.mk_dir(dir) # Make path wmo w_dir = utils.mk_path(dir, place.wmo) for yyyymmdd in dates: ymd = utils.f_to_s(yyyymmdd) # Get year, month and day y, m, d = ymd[:4], ymd[4:6], ymd[6:8] y_dir = utils.mk_path(w_dir, y) # Make path year m_dir = utils.mk_path(y_dir, m) # Make path month # Make path path = utils.mk_path(m_dir, f'dayvalues-{place.wmo}-{y}-{m}-{d}.{type}') # Make link html only link = utils.mk_path(dir, f'dayvalues.html?wmo={place.wmo}&date={y}{m}{d}') # if fio.path = Path(fname) # Python 3.4 if check: if Path(path).exists(): # Check if there is a file console.log(f'File {path} already found and skipped...', True) continue console.log(f'A file for station {place.place} for the date {ymd} will be made...', True) # Check and make directories ok = os.path.isdir(m_dir) if not ok: # Check and make necessary maps ok = fio.mk_dir(w_dir) if ok: # WMO map exists ok = fio.mk_dir(y_dir) if ok: # Year map exists ok = fio.mk_dir(m_dir) if ok: # Month map exists console.log(f'Map to write {m_dir} is ok!') else: console.log(f'Error! in map to write map {m_dir}') # Get correct day day = d1[np.where(dates == yyyymmdd)][0] path_to_root = './../../../../../' # Make output if type == 'html': header = f'<i class="text-info fas fa-home"></i> ' header += f'{place.wmo} - {place.place} ' header += f'{place.province} - {utils.ymd_to_txt(ymd)} ' page = vhtml.Template() page.title = f'{place.wmo} {place.place} {ymd}' page.header = header page.strip = True page.main = vhtml.main_ent( day ) page.footer = vhtml.footer_data_notification(place) page.file_path = path page.path_to_root = path_to_root page.template = utils.mk_path( config.dir_templates_html, 'dayvalues.html' ) # Styling page.css_files = [ f'{path_to_root}dayvalues/css/default.css', f'{path_to_root}dayvalues/css/dayvalues.css' ] page.script_files = [ f'{path_to_root}dayvalues/js/default.js', f'{path_to_root}static/js/default.js'] ok = page.save() if ok: console.log(f'Successfull made {path}', True) else: console.log(f'Failed to make {path}', True) console.log(' ', True) # elif type == 'txt': # title = txt_date # main = view_dayvalues.txt_main( day ) # txt = f'{title}\n{main}' # path = utils.mk_path( station.dayvalues_dir_txt, fname ) console.log(f'Link is {link}', True) return link
def calculate( stations, period, name=False, type='html' ): '''Function calculates summer statistics''' colspan = 20 # Make data list with station and summerstatistics summer = list() for station in stations: console.log(f'Calculate statistics: {station.place}', True) ok, data = daydata.read( station ) # Get data stations if ok: days = daydata.period( data, period ) # Get days of period if days.size != 0: # Skip station summer.append( Stats( station, days ) ) # Create summerstats object console.log(f'\nPreparing output: {type}', True) # Update name if there is none yet if not name: name = utils.mk_name('summerstatistics', period) # Make path if it is a html or txt file dir = utils.mk_path(cfg.dir_summerstats, type) path = utils.mk_path( dir, f'{name}.{type}' ) fio.mk_dir(dir) # Sort on TG summer = sort( summer, '+' ) # Make output title, main, footer = '', '', '' # Maak content op basis van type uitvoer html of text # Maak titel table_title = 'Summer statistics ' if type in ['txt','cmd']: s = ' ' title += f'{table_title} {period}\n' title += f'PLAATS{s:15} ' title += f'PROVINCIE{s:7} ' title += f'PERIODE{s:11} ' title += f'TG{s:5} ' title += f'WARMTE ' title += 'TX MAX ' title += 'TG MAX ' title += 'TN MAX ' title += 'TX≥20 ' title += 'TX≥25 ' title += 'TX≥30 ' title += 'TX≥35 ' title += 'TX≥40 ' title += 'TG≥20 ' title += 'TG≥18 ' title += 'TN≥20 ' title += 'ZON≥10 ' title += 'ZON{s:6} ' title += 'REGEN≥10 ' title += 'REGEN\n' if type == 'html': title += f''' <table id="stats"> <thead> <tr> <th colspan="{colspan}"> {icon.weather_all()} {table_title} {icon.wave_square()} {period} {icon.cal_period()} </th> </tr> <tr> <th title="copyright data_notification"> </th> <th> place {icon.home(size='fa-sm')}</th> <th> province {icon.flag(size='fa-sm')}</th> <th> period {icon.cal_period(size='fa-sm')}</th> <th title="Average temperature"> tg {icon.temp_half(size='fa-sm')}</th> <th title="Warmte getal"> heat {icon.fire(size='fa-sm')}</th> <th title="Warmste dag"> tx {icon.arrow_up(size='fa-sm')}</th> <th title="Hoogste gemiddelde"> tg {icon.arrow_up(size='fa-sm')}</th> <th title="Hoogste minimum"> tn {icon.arrow_up(size='fa-sm')}</th> <th title="Aantal warme dagen"> tx{icon.gte(size='fa-xs')}20 </th> <th title="Aantal zomers dagen"> tx{icon.gte(size='fa-xs')}25 </th> <th title="Aantal tropische dagen"> tx{icon.gte(size='fa-xs')}30 </th> <th title="Aantal tropische dagen"> tx{icon.gte(size='fa-xs')}35 </th> <th title="Aantal tropische dagen"> tx{icon.gte(size='fa-xs')}40 </th> <th title="Aantal tropennachten"> tn{icon.gte(size='fa-xs')}20 </th> <th title="Warmte getal dagen"> tg{icon.gte(size='fa-xs')}18 </th> <th title="Totaal aantal uren zon"> {icon.sun(size='fa-sm')} </th> <th title="Dagen met meer dan tien uur zon"> {icon.sun(size='fa-xs')}{icon.gte(size='fa-xs')}10h</th> <th title="Totaal aantal mm regen">{icon.shower_heavy(size='fa-sm')}</th> <th title="Dagen met meer dan tien mm regen"> {icon.shower_heavy(size='fa-xs')}{icon.gte(size='fa-xs')}10mm</th> </tr> </thead> <tbody> ''' # Walkthrough all cities for s in summer: console.log(f'Make {type} output for: {s.station.place}', True) heat = fix.ent( s.heat_ndx, 'heat_ndx' ) tg_gem = fix.ent( s.tg_gem, 'tg' ) tx_max = fix.ent( s.tx_max, 'tx' ) tg_max = fix.ent( s.tg_max, 'tg' ) tn_max = fix.ent( s.tn_max, 'tn' ) rh_tot = fix.ent( s.rh_tot, 'rh' ) sq_tot = fix.ent( s.sq_tot, 'sq' ) if type in ['txt','cmd']: main += f'{s.station.place:<21} ' main += f'{s.station.province:<16} ' main += f'{s.station.period:<18} ' main += f'{tg_gem:<7} ' main += f'{heat_ndx:<7} ' main += f'{tx_max:<7} ' main += f'{tg_max:<7} ' main += f'{tn_max:<7} ' main += f'{tx_gte_20:^6} ' main += f'{tx_gte_25:^6} ' main += f'{tx_gte_30:^6} ' main += f'{tx_gte_35:^6} ' main += f'{tg_gte_20:^6} ' main += f'{tg_gte_18:^6} ' main += f'{tn_gte_20:^6} ' main += f'{sq_gte_10:^7} ' main += f'{sq_tot:<10} ' main += f'{rh_gte_10:^9} ' main += f'{rh_tot:<11} ' if type == 'html': period_txt = f'{utils.ymd_to_txt(s.date_s)} - {utils.ymd_to_txt(s.date_e)}' main += f''' <td title="{s.station.data_notification.lower()}"> {icon.copy_light(size='fa-xs')} </td> <td> <span class="val"> {s.station.place} </span> </td> <td> <span class="val"> {s.station.province} </span> </td> <td title="{period_txt}"> <span class="val"> {s.period} </span> </td> <td> <span class="val"> {tg_gem} </span> </td> <td> <span class="val"> {heat} </span> {vhtml.table_heat_ndx(s.days_heat_ndx, 'TG')} </td> <td> <span class="val"> {tx_max} </span> {vhtml.table_days( s.tx_max_sort, 'TX', 'TXH' )} </td> <td> <span class="val"> {tg_max} </span> {vhtml.table_days( s.tg_max_sort, 'TG' )} </td> <td> <span class="val"> {tn_max} </span> {vhtml.table_days( s.tn_max_sort, 'TN', 'TNH' )} </td> <td> <span class="val"> {np.size(s.days_tx_gte_20, axis=0)} </span> {vhtml.table_days_count(s.days_tx_gte_20, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size(s.days_tx_gte_25, axis=0)} </span> {vhtml.table_days_count(s.days_tx_gte_25, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size(s.days_tx_gte_30, axis=0)} </span> {vhtml.table_days_count(s.days_tx_gte_30, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size(s.days_tx_gte_35, axis=0)} </span> {vhtml.table_days_count(s.days_tx_gte_35, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size(s.days_tx_gte_40, axis=0)} </span> {vhtml.table_days_count(s.days_tx_gte_40, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size(s.days_tn_gte_20, axis=0)} </span> {vhtml.table_days_count(s.days_tn_gte_20, 'TG' )} </td> <td> <span class="val"> {np.size(s.days_tg_gte_18, axis=0)} </span> {vhtml.table_days_count(s.days_tg_gte_18, 'TG' )} </td> <td> <span class="val"> {sq_tot} </span> {vhtml.table_days( s.sq_sort, 'SQ' )} </td> <td> <span class="val"> {np.size(s.days_sq_gte_10, axis=0)} </span> {vhtml.table_days_count(s.days_sq_gte_10, 'SQ', '' )} </td> <td> <span class="val"> {rh_tot} </span> {vhtml.table_days( s.rh_sort, 'RH' )} </td> <td> <span class="val"> {np.size(s.days_rh_gte_10, axis=0)} </span> {vhtml.table_days_count(s.days_rh_gte_10, 'RH', '' )} </td> </tr> ''' if type in ['txt','cmd']: footer += stations[0].data_notification if type == 'html': footer += f''' </tbody> <tfoot> <tr> <td colspan="{colspan}"> {utils.now_created_notification()} </td> </tr> </tfoot> </table> ''' console.log('\nWrite/print results... ', True) path_to_root = './../../' # Path to html root # Write to file or console output = f'{title}\n{main}\n{footer}' if type == 'cmd': console.log( output, True ) elif type == 'html': page = vhtml.Template() page.title = table_title page.main = output page.strip = True page.path_to_root = path_to_root page.file_path = path # Styling page.css_files = [ f'{path_to_root}summerstats/css/default.css', f'{path_to_root}static/css/table-statistics.css', f'{path_to_root}summerstats/css/summerstats.css' ] # Scripts page.script_files = [ f'{path_to_root}summerstats/js/summerstats.js', f'{path_to_root}static/js/sort-col.js', f'{path_to_root}static/js/default.js' ] page.save() elif type == 'txt': fio.save(path, output) # Schrijf naar bestand return path
def calculate(stations, period, name, type='html'): '''Function to calculate winterstatistics''' console.log(f'Preparing output...') colspan = 20 # Make data list with station and stats winter = list() for station in stations: console.log(f'Calculate statistics: {station.place}', True) ok, data = daydata.read(station) # Get data stations if ok: days = daydata.period(data, period) # Get days of period if days.size != 0: winter.append(Stats(station, days)) # Create winterstats object console.log(f'\nPreparing output: {type}', True) # Update name if there is none yet if not name: name = utils.mk_name('winterstatistics', period) # Make path if it is a html or txt file dir = utils.mk_path(cfg.dir_winterstats, type) path = utils.mk_path(dir, f'{name}.{type}') fio.mk_dir(dir) # Sort on hellmann winter = sort(winter, '+') # Make output title, main, footer = '', '', '' # Head of txt of console table_title = 'Winter statistics ' if type in ['txt', 'cmd']: title += f'{table_title} {period}\n' title += f'PLAATS{s:17} ' title += f'PROVINCIE{s:8} ' title += f'PERIODE{s:11} ' title += f'TG{s:5} ' title += 'HELLMANN TX MIN TG MIN TN MIN TX<0 TG<0 TN<0 TN<-5 ' title += 'TX<-10 TX<-15 TX<-20\n' if type == 'html': title += f''' <table id="stats"> <thead> <tr> <th colspan="{colspan}"> {icon.weather_all()} {table_title} {icon.wave_square()} {period} {icon.cal_period()} </th> </tr> <tr> <th title="copyright data_notification"> </th> <th> place {icon.home(size='fa-sm')}</th> <th> province {icon.flag(size='fa-sm')}</th> <th> period {icon.cal_period(size='fa-sm')}</th> <th title="Average temperature"> tg {icon.temp_half(size='fa-sm')}</th> <th title="Hellmann"> hmann {icon.icicles(size='fa-sm')}</th> <th title="IJnsen"> ijnsen {icon.icicles(size='fa-sm')}</th> <th title="Frost sum"> fsum {icon.icicles(size='fa-sm')}</th> <th title="Coldest maximum temperature"> tx {icon.arrow_down(size='fa-sm')}</th> <th title="Coldest average temperature "> tg {icon.arrow_down(size='fa-sm')}</th> <th title="Coldest minumum temperature"> tn {icon.arrow_down(size='fa-sm')}</th> <th title="Total hours sun"> {icon.sun(size='fa-sm')}</th> <th title="Total mm rain"> {icon.shower_heavy(size='fa-sm')} </th> <th title="Days with maximum temperature below 0 degrees celsius"> tx{icon.lt(size='fa-xs')}0 </th> <th title="Days with average temperature below 0 degrees celsius"> tg{icon.lt(size='fa-xs')}0 </th> <th title="Days with minimum temperature below 0 degrees celsius"> tn{icon.lt(size='fa-xs')}0 </th> <th title="Days with temperature lower than -5 degrees celsius"> tn{icon.lt(size='fa-xs')}−5 </th> <th title="Days with temperature lower than -10 degrees celsius"> tn{icon.lt(size='fa-xs')}−10 </th> <th title="Days with temperature lower than -15 degrees celsius"> tn{icon.lt(size='fa-xs')}−15 </th> <th title="Days with temperature lower than -20 degrees celsius"> tn{icon.lt(size='fa-xs')}−20 </th> </tr> </thead> <tbody> ''' # Calculate values for s in winter: console.log(f'Make {type} output for: {s.station.place}', True) tg_gem = fix.ent(s.tg_gem, 'TG') tx_min = fix.ent(s.tx_min, 'TX') tg_min = fix.ent(s.tg_min, 'TG') tn_min = fix.ent(s.tn_min, 'TN') hellmann = fix.ent(s.sum_hellmann, 'hellmann') f_sum = fix.ent(s.frost_sum, 'frost_sum') ijnsen = fix.ent(s.ijnsen, 'ijnsen') sq_sum = fix.ent(s.sq_sum, 'SQ') rh_sum = fix.ent(s.rh_sum, 'RH') if type == 'html': period_txt = f'{utils.ymd_to_txt(s.date_s)} - {utils.ymd_to_txt(s.date_e)}' # TODO the extension html tables main += f''' <tr class="row-data"> <td title="{s.station.data_notification.lower()}"> {icon.copy_light(size='fa-xs')} </td> <td> <span class="val"> {s.station.place} </span> </td> <td> <span class="val"> {s.station.province} </span> </td> <td title="{period_txt}"> <span class="val"> {s.period} </span> </td> <td> <span class="val"> {tg_gem} </span> </td> <td> <span class="val"> {hellmann} </span> {vhtml.table_hellmann( s.days_tg_lt_0 )} </td> <td> <span class="val"> {ijnsen} </span> </td> <td> <span class="val"> {f_sum} </span> {vhtml.table_frost_sum( s.frost_sum_data )} </td> <td> <span class="val"> {tx_min} </span> {vhtml.table_days( s.tx_min_sort, 'TX', 'TXH' )} </td> <td> <span class="val"> {tg_min} </span> {vhtml.table_days( s.tg_min_sort, 'TG' )} </td> <td> <span class="val"> {tn_min} </span> {vhtml.table_days( s.tn_min_sort, 'TN', 'TNH' )} </td> <td> <span class="val"> {sq_sum} </span> {vhtml.table_days( s.sq_sort, 'SQ' )} </td> <td> <span class="val"> {rh_sum} </span> {vhtml.table_days( s.rh_sort, 'RH' )} </td> <td> <span class="val"> {np.size( s.days_tx_lt_0, axis=0 )} </span> {vhtml.table_days_count( s.days_tx_lt_0, 'TX', 'TXH' )} </td> <td> <span class="val"> {np.size( s.days_tg_lt_0, axis=0 )} </span> {vhtml.table_days_count( s.days_tg_lt_0, 'TG' )} </td> <td> <span class="val"> {np.size( s.days_tn_lt_0, axis=0 )} </span> {vhtml.table_days_count( s.days_tn_lt_0, 'TN', 'TNH' )} </td> <td> <span class="val"> {np.size( s.days_tn_lt__5, axis=0 )} </span> {vhtml.table_days_count( s.days_tn_lt__5, 'TN', 'TNH' )} </td> <td> <span class="val"> {np.size( s.days_tn_lt__10, axis=0 )} </span> {vhtml.table_days_count( s.days_tn_lt__10, 'TN', 'TNH' )} </td> <td> <span class="val"> {np.size( s.days_tn_lt__15, axis=0 )} </span> {vhtml.table_days_count( s.days_tn_lt__15, 'TN', 'TNH' )} </td> <td> <span class="val"> {np.size( s.days_tn_lt__20, axis=0 )} </span> {vhtml.table_days_count( s.days_tn_lt__20, 'TN', 'TNH' )} </td> </tr> ''' elif type in ['txt', 'cmd']: main += f'{s.station.place:<23} ' main += f'{s.station.province:17} ' main += f'{s.station.period:18} ' main += f'{tg_gem:7} ' main += f'{hellmann:^8} ' main += f'{tx_min:<7} ' main += f'{tg_min:<7} ' main += f'{tn_min:<7} ' main += f'{np.size( s.days_tx_lt_0, axis=0 ):^5} ' main += f'{np.size( s.days_tg_lt_0, axis=0 ):^5} ' main += f'{np.size( s.days_tn_lt_0, axis=0 ):^5} ' main += f'{np.size( s.days_tn_lt__5, axis=0 ):^6} ' main += f'{np.size( s.days_tn_lt__10, axis=0 ):^6} ' main += f'{np.size( s.days_tn_lt__15, axis=0 ):^6} ' main += f'{np.size( s.days_tn_lt__20, axis=0 ):^6} \n' # Close of main, footer if type in ['txt', 'cmd']: footer += cfg.knmi_dayvalues_notification elif type == 'html': footer += f''' </tbody> <tfoot> <tr> <td colspan="{colspan}"> {utils.now_created_notification()} </td> </tr> </tfoot> </table> ''' path_to_root = './../../' # Path to html root console.log('\nWrite/print results... ', True) # Write to file or console output = f'{title}\n{main}\n{footer}' if type == 'cmd': console.log(output, True) elif type == 'html': page = vhtml.Template() page.title = table_title page.main = output page.strip = True page.path_to_root = path_to_root page.file_path = path # Styling page.css_files = [ f'{path_to_root}winterstats/css/default.css', f'{path_to_root}static/css/table-statistics.css', f'{path_to_root}winterstats/css/winterstats.css' ] # Scripts page.script_files = [ f'{path_to_root}winterstats/js/winterstats.js', f'{path_to_root}static/js/sort-col.js', f'{path_to_root}static/js/default.js' ] page.save() elif type == 'txt': fio.save(path, output) # Schrijf naar bestand return path