-
Notifications
You must be signed in to change notification settings - Fork 0
/
monthly_production.py
82 lines (53 loc) · 1.87 KB
/
monthly_production.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, os
import pandas as pd
from importlib import reload
from bs4 import BeautifulSoup
import urllib.request
from tqdm import tqdm
import numpy as np
import PROFILE_READER.config as conf
base_dir = conf.BASE_DIR
import grimsel.auxiliary.timemap as timemap
from grimsel.auxiliary.aux_general import read_xlsx_table
from xlrd import open_workbook
import PROFILE_READER.profile_reader as profile_reader
reload(profile_reader)
class MonthlyProductionReader(profile_reader.ProfileReader):
'''
'''
dict_sql_default = dict(sc='profiles_raw', tb='monthly_production')
data_dir = os.path.normpath('VARIOUS_SOURCES_MONTHLY_SUMS')
tb_cols = [('fl', 'VARCHAR'),
('mt_id', 'SMALLINT'),
('nd', 'VARCHAR'),
('run_id', 'SMALLINT'),
('year', 'SMALLINT'),
('erg', 'DOUBLE PRECISION'),
('input', 'VARCHAR')]
tb_pk = ['fl', 'mt_id', 'year', 'nd', 'input', 'run_id']
exclude_substrings=[]
def __init__(self, kw_dict):
super().__init__(**kw_dict)
self.get_fn_list()
def read(self, fn):
wb = open_workbook(fn)
df_add = read_xlsx_table(wb, sheets=['2015', 'OTHER_YEARS'],
columns=['fl', 'mt_id', 'nd', 'run_id',
'year', 'erg', 'input'])
return df_add
def read_all(self):
fn = self.fn_list[0]
self.df_tot = self.read(fn)
self.append_to_sql(self.df_tot)
if __name__ == '__main__':
kw_dict = dict(dict_sql=dict(db='storage2'),
exclude_substrings=[],
tm_filt={'year': range(2005, 2018)},
ext=['xlsx'], base_dir=base_dir)
op = MonthlyProductionReader(kw_dict)
self = op
fn = self.fn_list[0]
op.read_all()
# %%