Untitled

 avatar
unknown
plain_text
5 months ago
3.8 kB
4
Indexable
if __name__ == "__main__":
    # logging.basicConfig(
    #     level=logging.DEBUG,
    #     format=('%(asctime)s (%(filename)s:%(lineno)s) '
    #             '%(levelname)s: %(message)s')
    #     , filename=logsfolder + r'/log_{}.log'.format(REPORT_DATE)
    # )

    logging.getLogger('requests').setLevel(logging.WARNING)
    import warnings
    warnings.simplefilter(action='ignore', category=FutureWarning)

    # print(logging.Logger.manager.loggerDict)
    # logging.getLogger('requests').setLevel(logging.WARNING)
  
    RT_OR_NIGHT = 'night'
#     #sys.exit()
    if RT_OR_NIGHT == 'night':
        ### Comment appropriately for local runs ###
        st_accounts = find_ci_st_accounts(env=WRITE_ENVIRONMENT, queued_accounts=[])
        # st_accounts = st_accounts[:3]
        # st_accounts = [(4122886, '56085093'), (7709226, '2411481034')]
        # st_accounts = retrive_ci_queued_accounts(RT_OR_NIGHT='night')
        st_accounts = st_accounts[:20]
        # st_accounts = [(153279,70153),(210805,68804)]
        if len(st_accounts) > 0:
            id_station_mapping = get_acct_and_cust_ids(env=READ_ENVIRONMENT, accountids=st_accounts)
            st_accounts_to_work = list(id_station_mapping.index)
            st_accounts_no_weather = list(set(st_accounts) - set(st_accounts_to_work))
            if len(st_accounts_no_weather) > 0:
                print("There are " + str(
                    len(st_accounts_no_weather)) + " st accounts which cannot find weather station (not in [Forecasts].[ForecastAccountByMeter])")
                logger.info("There are " + str(
                    len(st_accounts_no_weather)) + " st accounts which cannot find weather station (not in [Forecasts].[ForecastAccountByMeter])")
                telemetry_client.track_event("There are " + str(
                    len(st_accounts_no_weather)) + " st accounts which cannot find weather station (not in [Forecasts].[ForecastAccountByMeter]", {'Status': 'Success'})
                write_no_weather_accts_to_error_database(st_accounts_no_weather)
            print("ST forecast starts for " + str(len(st_accounts_to_work)) + " accounts")
            logger.info("ST forecast starts for " + str(len(st_accounts_to_work)) + " accounts")
            telemetry_client.track_event("ST forecast starts for " + str(len(st_accounts_to_work)) + " accounts", {'Status': 'Success'})
            # st_accounts_to_work = [(159332, np.nan), (159336, np.nan), (159337, np.nan)]
            if len(st_accounts_to_work) > 0:
                # do short-term and three-day backcast and write to database
                forecast(accountids=st_accounts_to_work,
                         start_date=pd.to_datetime(REPORT_DATE).floor('d') - pd.DateOffset(days=3),
                         end_date=pd.to_datetime(REPORT_DATE).floor('d'),
                         short_term=True, weather_norm=False, historical_backcast=True, write_to_database=True,
                         keep_historical=None, plot_graphs=False, save_to_table=False,
                         id_station_mapping=id_station_mapping)
                # do short-term, long-term, and backcast and do plotting and write to excel
                # forecast(accountids=st_accounts_to_work, start_date=start_date, end_date=pd.to_datetime('today').floor('d'),
                #          short_term = True, weather_norm = True, historical_backcast = True, write_to_database=False, keep_historical=None, plot_graphs=True, save_to_table=True, id_station_mapping=id_station_mapping)

        print("Process complete")
        logger.info("Process Complete")
        telemetry_client.track_event("Process Complete", {'Status': 'Success'})
        telemetry_client.flush()
Editor is loading...
Leave a Comment