예제 #1
0
    reader = csv.reader(arquivo_csv, delimiter=',')
    year = 2013
    month = 1

    collection = 'historical_data_daily'

    for colunm in reader:
        if year < 2021:
            for week in calendar.monthcalendar(year, month):
                for day in week:
                    if day != 0:
                        date = utils.format_number(
                            day, 2) + '.' + utils.format_number(
                                month, 2) + '.' + str(year)
                        date = utils.string_to_date(date)
                        if server.db_select(collection, ['date'],
                                            [date]) == None:
                            server.db_insert(
                                collection, ['date', 'br_production'],
                                [date, utils.string_to_float(colunm[1])])
                        else:
                            server.db_update(collection, {"date": date}, {
                                'br_production':
                                utils.string_to_float(colunm[1])
                            })

                        if server.db_select(collection, ['date'],
                                            [date]) == None:
                            server.db_insert(
                                collection, ['date', 'br_plateau_area'],
                                [date, utils.string_to_float(colunm[2])])
                        else:
예제 #2
0
        if idx > 1:
            collection = 'historical_data_weekly'
            keys = [
                'date', 'dolar', 'open_dolar', 'max_dolar', 'min_dolar',
                'var_dolar'
            ]
            values = [
                utils.string_to_date(colunm[0]),
                utils.string_to_float(colunm[1]),
                utils.string_to_float(colunm[2]),
                utils.string_to_float(colunm[3]),
                utils.string_to_float(colunm[4]),
                utils.string_to_float(colunm[5])
            ]
            colunm[0] = utils.string_to_date(colunm[0]) - timedelta(days=1)
            if server.db_select(collection, [keys[0]], [values[0]]) == None:
                server.db_insert(collection, keys, values)
            else:
                for i, *_ in enumerate(colunm):
                    if i >= 1:
                        server.db_update(collection, {keys[0]: values[0]},
                                         {keys[i]: values[i]})

with open('../files/dolar_brl_historio.csv', 'r') as arquivo_csv:
    reader = csv.reader(arquivo_csv, delimiter=',')
    for idx, colunm in enumerate(reader):
        if idx > 1:
            collection = 'historical_data_daily'
            keys = [
                'date', 'dolar', 'open_dolar', 'max_dolar', 'min_dolar',
                'var_dolar'
예제 #3
0
            "$lt": dt.datetime(2019, 1, 1)
        }
    }, {
        "corn_br": {
            "$ne": 0
        }
    }]
}

writer.writerow([
    "date", "corn_usd", "br_production", "br_plateau_area", "br_productivity",
    "dolar", "corn_br_-1", "corn_br"
])
corn_one_day_before = 0

for item in server.db_select('historical_data_daily', _query=query):
    date = item.get('date')
    corn_br = item.get('corn_br')
    corn_usd = item.get('corn_usd')
    br_production = item.get('br_production')
    br_plateau_area = item.get('br_plateau_area')
    br_productivity = item.get('br_productivity')
    dolar = item.get('dolar')

    if corn_br and corn_usd and br_production and br_plateau_area and br_productivity and dolar:

        date_corn_one_day_before = date - timedelta(days=1)

        for i in server.db_select('historical_data_daily',
                                  _query={"date": date_corn_one_day_before}):
            if i.get('corn_br'):
예제 #4
0
writer = csv.writer(open("../files/dataset_2.csv", 'w'))

writer.writerow(['date', 'corn_br', 'corn_usd', 'dolar', 'corn_br-1', 'corn_br-2', 'corn_br-3', 'max_corn_br-1', 'min_corn_br-1', 'open_corn_br-1', 'var_corn_br-1', 'vol_corn_br-1']) 

year = 2011
month = 1

corn_br_days_before = [{}, {}, {}]
print(corn_br_days_before )

while year <= 2019 and month <= 12:
    for *week, _, _ in calendar.monthcalendar(year, month):
        for day in week:
            if day != 0:
                results = server.db_select('historical_data_daily', ['date'], [dt.datetime(year, month, day)])
                
                if results.get('corn_br'):
                    copy_results = results.copy()
                    corn_br_days_before.append(copy_results)

                    corn_3_before = corn_br_days_before.pop(0)
                    corn_2_before = corn_br_days_before[-3]
                    corn_1_before = corn_br_days_before[-2]



                    max_corn_br_1_before = get_last_not_null_value('max_corn_br', corn_1_before, corn_2_before, corn_3_before)
                    min_corn_br_1_before = get_last_not_null_value('min_corn_br', corn_1_before, corn_2_before, corn_3_before)
                    open_corn_br_1_before = get_last_not_null_value('open_corn_br', corn_1_before, corn_2_before, corn_3_before)
                    var_corn_br_1_before = get_last_not_null_value('var_corn_br', corn_1_before, corn_2_before, corn_3_before)
예제 #5
0
print('\n\nImportando dados Semanais do Preço do Milho\n\n')
with open('../files/milho_br_semanal.csv', 'r') as arquivo_csv:
    reader = csv.reader(arquivo_csv, delimiter = ',')
    for idx, colunm in enumerate(reader):
        if idx > 1:
            date = colunm[0].replace(',','')
            date = date.split(' ')
            date = utils.format_number(date[1], 2) + '.' + utils.format_number(str(utils.mounth_numeric.get(date[0])), 2) + '.' + date[2]

            collection = 'historical_data_weekly'
            keys = ['date', 'corn_br', 'open_corn_br', 'max_corn_br', 'min_corn_br', 'vol_corn_br', 'var_corn_br']
            values = [utils.string_to_date(date), utils.string_to_float(colunm[1]), utils.string_to_float(colunm[2]), utils.string_to_float(colunm[3]), utils.string_to_float(colunm[4]), utils.string_to_float(colunm[5]), utils.string_to_float(colunm[6])]


            if server.db_select(collection, [keys[0]], [utils.string_to_date(date)]) == None:
                server.db_insert(collection, keys, values)
            else:
                for i, *_ in enumerate(colunm):
                    if i >= 1:
                        server.db_update(collection, {keys[0]: values[0]}, {keys[i]: values[i]})

print('\n\nImportando dados Diarios do Preço do Milho\n\n')
with open('../files/milho_br.csv', 'r') as arquivo_csv:
    reader = csv.reader(arquivo_csv, delimiter = ',')
    for idx, colunm in enumerate(reader):
        if idx > 1:
            collection = 'historical_data_daily'
            keys = ['date', 'corn_br', 'open_corn_br', 'max_corn_br', 'min_corn_br', 'vol_corn_br', 'var_corn_br']
            values = [colunm[0], utils.string_to_float(colunm[1]), utils.string_to_float(colunm[2]), utils.string_to_float(colunm[3]), utils.string_to_float(colunm[4]), utils.string_to_float(colunm[5]), utils.string_to_float(colunm[6])]