Ejemplo n.º 1
0
def table_allstats():
    '''Function makes calculations for all statistics'''
    while True:
        console.header('START CALCULATE ALL STATISTICS...', True)
        # Ask for all in one
        ok, period, places, type, name = cask.ask_period_stations_type_name(
            'all')
        if not ok: break

        console.header(f'CALCULATING ALL STATISTICS...', True)

        st = time.time_ns()
        path = allstats.calculate(places, period, name, type)
        console.log(vt.process_time('Total processing time is ', st), True)

        if type != 'cmd':
            fopen = cask.ask_to_open_with_app(
                f'\nOpen the file (type={type}) with your default application ?'
            )
            if fopen: fio.open_with_app(path, 2, True)

        # Always ask for going back
        again = cask.ask_again(
            f'\nDo you want to make another all statistics table ?')
        if utils.is_quit(again):
            break

    console.footer(f'END CALCULATE ALL STATISTICS...', True)
Ejemplo n.º 2
0
def process_knmi_dayvalues_selected():
    '''Function asks for one or more wmo numbers to download their data'''
    console.header('START DOWNLOAD STATION(S) KNMI DATA DAY VALUES...', True)

    done, max = 0, (stations.list)
    while True:

        places = cask.ask_for_stations('\nSelect one or more stations ? ',
                                       stations.list)
        if utils.is_quit(places):
            break

        st = time.time_ns()
        for stat in places:
            daydata.process_data(stat)
            console.log(' ', True)

        console.log(vt.process_time('Total processing time is ', st), True)

        again = cask.ask_again(f'Do you want to download more stations ?',
                               True)
        if utils.is_quit(again):
            break

    console.footer('END DOWNLOAD STATION(S) KNMI DATA DAY VALUES...', True)
Ejemplo n.º 3
0
def process_knmi_dayvalues_all():
    '''Function downloads, unzipped  all knmi stations in the list'''
    console.header('START DOWNLOADING ALL DATA DAYVALUES KNMI STATIONS...',
                   True)
    st = time.time_ns()
    for stat in stations.list:
        daydata.process_data(stat)

    console.log(vt.process_time('Total processing time is ', st), True)
    console.footer('END DOWNLOADING ALL STATIONS KNMI DATA DAY VALUES', True)
    cask.ask_back_to_main_menu()
Ejemplo n.º 4
0
def main_menu():
    while True:  # Main menu
        ok_web, ok_data, loc_menu = check_menu_options()
        num = 1
        console.header('MAIN MENU', True )

        for el in loc_menu:
            title, options = el[0], el[1]
            console.log(f'\t{title}', True)
            for option in options:
                title, fn = option[0], option[1]
                console.log(f'\t\t{num}) {title}', True)
                num += 1
            print('')

        if ok_data == False and ok_web == False:
            t  = '\tNo internet and no data! Not much can be done now.\n'
            t += '\tFirst.  Try to have a working internet connection.\n'
            t += '\tSecond. Press a key to reload the menu or restart the application.\n'
            t += '\tThird.  Download weatherdata from the download options in the menu.'
            console.log(t, True)
            console.footer("\tPress a key to reload menu or press 'q' to quit...", True )
            answ = ask.ask(' ? ')
            if answ in cfg.answer_quit:
                break
            else:
                answ = False
        else:
            if ok_web == False:
                t = '\tNo internet connection. Get an working internet connection for more menu options.'
                console.log(t, True )
            elif ok_data == False:
                t = '\tNo data found. Download the weather data (option 1 & 2) for more menu options.'
                console.log(t, True )

            console.log(f'\tChoose one of the following options: 1...{num-1}', True )
            console.log(f"\tPress 'q' to quit...", True )
            console.footer('Your choice is ? ', True )
            answ = ask.ask(' ? ')  # Make a choice

        if not answ:
            continue
        elif answ in cfg.answer_quit:
            break
        else:
            try:
                choice = int(answ)
            except ValueError:
                console.log(f'\nOption "{answ}" unknown...', True ) # Input was not a number
            else:
                if choice in range( 1, num ):
                    fn_exec(choice, loc_menu)
                else:
                    console.log(f'\nOption "{answ}" out of reach', True )
Ejemplo n.º 5
0
def search_for_days():
    '''Function searches files for days with specific values. ie > 30 degrees'''
    while True:
        console.header('START SEARCHING FOR SPECIFIC DAYS...', True)

        period = cask.ask_for_period(
            '\nFor which time periode do you want to search ? ')
        if utils.is_quit(period): break

        places = cask.ask_for_stations(
            '\nSelect one or more weather stations ?')
        if not places:
            cask.ask_back_to_main_menu()
            break
        elif utils.is_quit(places):
            break

        query = cask.ask_for_query('\nType in a query for selecting days ? ')
        if utils.is_quit(query):
            break

        type = cask.ask_for_file_type('\nSelect output filetype ? ',
                                      cfg.default_output)
        if utils.is_quit(type):
            break

        fname = f'days-{utils.make_query_txt_only(query)}-{period}-{utils.now_for_file()}'
        fname = fname.replace('*', 'x').replace(' ', '')
        fname = cask.ask_for_file_name(
            '\nGive a name for the file ? <optional>', fname)
        if utils.is_quit(fname):
            break

        st = time.time_ns()
        path = search4days.calculate(places, period, query, type, fname)
        console.log(vt.process_time('Total processing time is ', st), True)

        if type in ['text', 'html']:
            fopen = cask.ask_to_open_with_app(
                f'\nOpen the file (type={type}) with your default application ?'
            )
            if fopen:
                fio.open_with_app(path, 2, True)

        # Always ask for going back
        again = cask.ask_again(f'Do you want to search for days again ?', True)
        if utils.is_quit(again):
            break

    console.footer('END SEARCH FOR DAYS...', True)
Ejemplo n.º 6
0
def get_dayvalues_by_date():
    '''Funtion gets day values from data knmi '''
    while True:
        console.header('START: SEARCHING AND PREPARING DAY VALUES...', True)
        # Ask for station

        places = cask.ask_for_stations(
            '\nSelect one or more weather stations ?')  # QUESTION: # QUESTION:
        if not places: break
        elif utils.is_quit(places): break

        period = cask.ask_for_period(
            '\nSelect one date or period(s) for the dayvalues ? ')
        if utils.is_quit(period): break

        type = cask.ask_for_file_type('\nSelect output filetype ? ',
                                      cfg.default_output)
        if utils.is_quit(type): break

        download = cask.ask_for_yn(
            '\nDo you want to download the data first ?', 'no')
        if utils.is_quit(download): break
        download = True if utils.is_yes(download) else False

        check = cask.ask_type_options(
            '\nDo you want to add only new files or rewrite it all ? ',
            ['add', 'rewrite'], 'add')
        if utils.is_quit(check): break
        console.log('CHECK-1: ' + str(check))
        check = True if check == 'add' else False
        console.log('CHECK-2: ' + str(check))

        st = time.time_ns()
        path = mdayval.calculate(places, period, type, check, download)
        console.log(vt.process_time('Total processing time is ', st), True)

        fopen = cask.ask_to_open_with_app(
            f'\nOpen the (last made) file (type={type}) with your default application ?'
        )
        if fopen:
            fio.open_with_app(path)

        # Always ask for going back
        t = f'\nDo you want to select another period(s) and or station(s) ?'
        again = cask.ask_again(t)
        if utils.is_quit(again):
            break

    console.footer('END SEARCHING AND PREPARING DAY VALUES...', True)
Ejemplo n.º 7
0
def month_extremes():
    '''Function calculates extremes in a month in'''
    while True:
        console.header('START CALCULATE EXTREMES IN A MONTH...', True)

        month = cask.ask_for_a_month(
            '\nFor which month do you want to calculate the extremes ? ')
        if utils.is_quit(month): break

        period = cask.ask_for_period(
            f'\nFor what time periode do you want to caculate the extremes in the month {month} ? '
        )
        if utils.is_quit(period): break

        places = cask.ask_for_stations(
            '\nSelect one or more weather stations ? ')
        if utils.is_quit(places): break

        type = cask.ask_for_file_type('\nSelect output filetype ? ',
                                      cfg.default_output)
        if utils.is_quit(type): break

        fname = f'monthextremes-{month}-{period}-{utils.now_for_file()}'
        fname = fname.replace('*', 'x').replace(' ', '')
        fname = cask.ask_for_file_name(
            '\nGive a name for the file ? <optional>', fname)
        if utils.is_quit(fname): break

        st = time.time_ns()
        path = mmonthextremes.calculate(places, period, month, type, fname)
        console.log(vt.process_time('Total processing time is ', st), True)

        if type in ['text', 'html']:
            fopen = cask.ask_to_open_with_app(
                f'\nOpen the file (type={type}) with your default application ?'
            )
            if fopen:
                fio.open_with_app(path, 2, True)

        # Always ask for going back
        again = cask.ask_again(
            f'Do you want to calculate extremes for a month again ?', True)
        if utils.is_quit(again):
            break

    console.footer('END CALCULATE EXTREMES IN A MONTH...', True)
Ejemplo n.º 8
0
def process_weather_knmi_current():
    '''Function downloads and print a actual weather values to the screen'''
    console.header('START DOWNLOAD CURRENT VALUES KNMI WEATHERSTATIONS...',
                   True)

    ok, t = False, ''
    if utils.has_internet():
        ok, t = mcurweather.knmi_stations()
        if ok:
            t = '\n' + vt.clean_up(t)
            console.log(t, True)
        else:
            console.log('Not ok. Something went wrong along the way.', True)
    else:
        console.log('No internet connection...', True)

    console.footer('END DOWNLOAD CURRENT VALUES KNMI WEATHERSTATIONS...', True)
    cask.ask_back_to_main_menu()
Ejemplo n.º 9
0
def process_weather_buienradar_global():
    '''Function downloads and print a global weather forecast from the website from the knmi'''
    console.header('START DOWNLOAD BUIENRADAR GLOBAL FORECAST...', True)

    ok = False
    if utils.has_internet():
        t, url = '', cfg.buienradar_json_data
        ok, t = mcurweather.buienradar_weather()
        if ok:
            t = '\n' + vt.clean_up(t)
            console.log(t, True)
        else:
            console.log('Not ok. Something went wrong along the way.', True)
    else:
        console.log('No internet connection...', True)

    console.footer('END DOWNLOAD BUIENRADAR GLOBAL FORECAST...', True)
    cask.ask_back_to_main_menu()
Ejemplo n.º 10
0
def year_extremes():
    '''Function calculates extremes in a year'''
    while True:
        console.header('START CALCULATE EXTREMES IN A YEAR...', True)

        year = cask.ask_for_a_year('\nSelect a year for the extremes ? ')
        if utils.is_quit(year): break

        places = cask.ask_for_stations(
            '\nSelect one or more weather stations ? ')
        if utils.is_quit(places): break

        type = cask.ask_for_file_type('\nSelect output filetype ? ',
                                      cfg.default_output)
        if utils.is_quit(type): break

        fname = f'yearextremes-{year}-{utils.now_for_file()}'
        fname = fname.replace('*', 'x').replace(' ', '')
        fname = cask.ask_for_file_name(
            '\nGive a name for the file ? <optional>', fname)
        if utils.is_quit(fname): break

        st = time.time_ns()
        path = myearextremes.calculate(places, year, type, fname)
        console.log(vt.process_time('Total processing time is ', st), True)

        if type in ['text', 'html']:
            fopen = cask.ask_to_open_with_app(
                f'\nOpen the file (type={type}) with your default application ?'
            )
            if fopen:
                fio.open_with_app(path)

        # Always ask for going back
        again = cask.ask_again(
            f'Do you want to calculate extremes for a year again ?', True)
        if utils.is_quit(again):
            break

    console.footer('END CALCULATE EXTREMES IN A YEAR...', True)
Ejemplo n.º 11
0
def process_weather_knmi_global():
    '''Function downloads and print a global weather forecast from the website from the knmi'''
    console.header('START DOWNLOAD KNMI GLOBAL FORECAST...', True)

    ok, t = False, ''
    if utils.has_internet():
        sd = utils.loc_date_now().strftime('%Y%m%d')
        url = cfg.knmi_forecast_global_url
        file = utils.mk_path(cfg.dir_forecasts_txt,
                             f'basisverwachting-{sd}.txt')
        ok = fio.download(url, file)
        if ok:
            ok, t = fio.read(file)
            if ok:
                t = '\n' + vt.clean_up(t)
                console.log(t, True)
            else:
                console.log('Not ok. Something went wrong along the way.',
                            True)
    else:
        console.log('No internet connection...', True)

    console.footer('END DOWNLOAD KNMI GLOBAL FORECAST...', True)
    cask.ask_back_to_main_menu()
Ejemplo n.º 12
0
def process_weather_knmi_guidance():
    '''Function downloads and prints a global a more in depth forecast from the website from the knmi'''
    console.header('START DOWNLOAD KNMI GUIDANCE...', True)

    ok, t = False, ''
    if utils.has_internet():
        sd = utils.loc_date_now().strftime('%Y%m%d')
        url = cfg.knmi_forecast_guidance_url
        name = f'guidance_meerdaagse-{sd}.txt'
        file = utils.mk_path(cfg.dir_forecasts_txt, name)
        ok = fio.download(url, file)
        if ok:
            ok, t = fio.read(file)
            if ok:
                t = '\n' + vt.clean_up(t)
                console.log(t, True)
            else:
                console.log('Not ok. Something went wrong along the way.',
                            True)
    else:
        console.log('No internet connection...', True)

    console.footer('END DOWNLOAD KNMI GUIDANCE...', True)
    cask.ask_back_to_main_menu()
Ejemplo n.º 13
0
def process_weather_knmi_model():
    '''Function downloads and prints a discussion about the weather models from the website from the knmi'''
    console.header('START DOWNLOAD KNMI DISCUSSION WEATHER MODELS...', True)

    ok, t = False, ''
    if utils.has_internet():
        sd = utils.loc_date_now().strftime('%Y%m%d')
        url = cfg.knmi_forecast_model_url
        name = f'guidance_model-{sd}.txt'
        file = utils.mk_path(cfg.dir_forecasts_txt, name)
        ok = fio.download(url, file)
        if ok:
            ok, t = fio.read(file)
            if ok:
                t = '\n' + vt.clean_up(t)
                console.log(t, True)
            else:
                console.log('Not ok. Something went wrong along the way.',
                            True)
    else:
        console.log('No internet connection...', True)

    console.footer('END DOWNLOAD KNMI DISCUSSION WEATHER MODELS...', True)
    cask.ask_back_to_main_menu()
Ejemplo n.º 14
0
def graph_period():
    '''Funtion makes images for a period from the data of the knmi'''
    while True:
        console.header('START MAKING A IMAGE GRAPH...', True)

        period = cask.ask_for_period('What time periode ?')
        if utils.is_quit(period):
            break

        places = cask.ask_for_stations('\nSelect weather station(s) ?')
        if not places:
            cask.ask_back_to_main_menu()
            break
        elif utils.is_quit(places):
            break

        entities = cask.ask_for_entities('\nSelect weather entity(s) ?')
        if utils.is_quit(entities):
            break

        ent_type_graphs = list()
        for ent in entities:
            ent_type = ent.upper()
            # Set to none or defaults
            graph_type = cfg.plot_graph_type
            line_width = cfg.plot_line_width
            marker_size = cfg.plot_marker_size
            marker_text = cfg.plot_marker_txt
            min_max_ave_period = cfg.plot_min_max_ave_period
            climate_ave = cfg.plot_climate_ave
            climate_ave_marker_txt = cfg.plot_climate_marker_txt
            climate_periode = cfg.climate_period

            graph_type = cask.ask_type_options(
                f'\nWhich type graph do you want to use for {ent_type} ? ',
                ['line', 'bar'], cfg.plot_graph_type)
            if utils.is_quit(graph_type):
                break
                break

            if graph_type == 'line':  # TODO MAKE OPTIONS FOR EACH ENTITIY COLOR OPTIONS
                line_width = cask.ask_for_int(
                    f'\nSet the width of the line (in pixels) for {ent_type} ? ',
                    cfg.plot_line_width)  # Width line
                if utils.is_quit(line_width):
                    break
                    break

                marker_size = cask.ask_for_int(
                    f'\nSet the marker size (in pixels) for {ent_type} ? ',
                    cfg.plot_marker_size)  # Dot sizes on day
                if utils.is_quit(marker_size):
                    break
                    break

            marker_txt = cask.ask_for_yn(
                f'\nValues next to the markers for {ent_type} ?  ',
                cfg.plot_marker_txt)
            if utils.is_quit(marker_txt):
                break
                break

            min_max_ave_period = cask.ask_for_yn(
                '\nCalculate min, max and average value in period too ? ',
                cfg.plot_min_max_ave_period)
            if utils.is_quit(min_max_ave_period):
                break
                break

            climate_ave = cask.ask_for_yn(
                f'\nCalculate and plot the climate averages for {ent_type} ? ',
                cfg.plot_climate_ave)
            if utils.is_quit(climate_ave):
                break
                break

            if utils.is_yes(climate_ave):
                climate_ave_marker_txt = cask.ask_for_yn(
                    f'\nValues next to the markers for climate averages for {ent_type} ? ',
                    cfg.plot_climate_marker_txt)
                if utils.is_quit(climate_ave_marker_txt):
                    break
                    break

                sy, ey = cfg.climate_period.split('-')
                climate_y_s = cask.ask_for_int(
                    f'\nGive a start year for the calculation of climate averages <yyyy> for {ent_type} ? ',
                    sy)
                if utils.is_quit(climate_y_s):
                    break
                    break
                climate_y_e = cask.ask_for_int(
                    f'\nGive an end year for the calculation of climate average <yyyy> for {ent_type} ? ',
                    ey)
                if utils.is_quit(climate_y_e):
                    break
                    break

                climate_periode = f'{climate_y_s}-{climate_y_e}'

            ent_type_graphs.append([
                ent_type, graph_type, line_width, marker_size, marker_text,
                min_max_ave_period, climate_ave, climate_ave_marker_txt,
                climate_periode
            ])

        console.log('Fill in the parameters for the image', False)
        title = cask.ask_for_txt('\nGive a title for the graph')
        ylabel = cask.ask_for_txt('\nGive a y-as label for the graph')
        default = cask.ask_for_yn(
            '\nDo you want to use default values ?\nSee file -> config.py...',
            cfg.plot_default)
        if utils.is_quit(default): break

        # Make option list
        options = {
            'plot_width': cfg.plot_width,
            'plot_height': cfg.plot_height,
            'plot_cummul_val': cfg.plot_cummul_val,
            'plot_image_type': cfg.plot_image_type,
            'plot_dpi': cfg.plot_dpi
        }

        if utils.is_no(default):
            # Update option list
            plot_width = cask.ask_for_int(
                '\nGive the width (in pixels) for the graph.', cfg.plot_width)
            if utils.is_quit(plot_width): break
            else: options['plot_width'] = plot_width

            plot_height = cask.ask_for_int(
                '\nGive the height (in pixels) for the graph.',
                cfg.plot_height)
            if utils.is_quit(plot_height): break
            else: options['plot_height'] = plot_height

            plot_cummul_val = cask.ask_for_yn(
                '\nDo you want cummulative values for the graph ? ',
                cfg.plot_cummul_val)
            if utils.is_quit(plot_cummul_val): break
            else:
                options[
                    'plot_cummul_val'] = plot_cummul_val  # Take first yess or no

            plot_image_type = cask.ask_type_options(
                '\nWhat type of image ? ', ['png', 'jpg', 'ps', 'pdf', 'svg'],
                cfg.plot_image_type)
            if utils.is_quit(plot_image_type): break
            else: options['plot_image_type'] = plot_image_type

            plot_dpi = cask.ask_for_int('\nGive the dpi ? ', cfg.plot_dpi)
            if utils.is_quit(plot_dpi): break
            else: options['plot_dpi'] = plot_dpi

        fname = f"graph-{period.replace('*', 'x')}-{utils.now_for_file()}"
        fname = cask.ask_for_file_name('\nGive a name for the file ? ', fname)
        if utils.is_quit(fname):
            break

        console.header('PREPARING IMAGES...', True)
        st = time.time_ns()
        path = vg.plot(places, ent_type_graphs, period, title, ylabel, fname,
                       options)
        console.log(vt.process_time('Total processing time is ', st), True)

        fopen = cask.ask_to_open_with_app(
            f'\nOpen the file (type={options["plot_image_type"]}) with your default application ?'
        )
        if fopen: fio.open_with_app(path)

        # Always ask for going back
        again = cask.ask_again(f'\nDo you want to make more images ?')
        if utils.is_quit(again):
            break

    console.footer('END MAKING A IMAGE GRAPH...', True)
Ejemplo n.º 15
0
def error_no_stations_found():
    console.header('No weatherstations found in configuration file !', True )
    console.log('Add one or more weatherstations in stations.py', True )
    console.footer('Press a key to quit...', True )
    input('...')