update_with_add_mask.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. import pymongo
  2. import datetime
  3. from sqlmask_converter import sqlmask_converter
  4. from config_info.config import *
  5. db_client = pymongo.MongoClient(DB_URL)
  6. prisma_db = db_client["prisma-32_db"]
  7. def update_with_add_mask(date_, binary_n_mask_1, binary_amp_mask_1, binary_n_mask_2, binary_amp_mask_2):
  8. collection_prisma = prisma_db[f'{str(date_)}_12d']
  9. upd_n_result_1 = collection_prisma.update_many({'cluster': 1}, {"$set": binary_n_mask_1[str(date_)]})
  10. print(f'Added n_mask_1 - {upd_n_result_1.raw_result}')
  11. upd_amp_result_1 = collection_prisma.update_many({'cluster': 1}, {"$set": binary_amp_mask_1[str(date_)]})
  12. print(f'Added amp_mask_1 - {upd_amp_result_1.raw_result}')
  13. upd_n_result_2 = collection_prisma.update_many({'cluster': 2}, {"$set": binary_n_mask_2[str(date_)]})
  14. print(f'Added n_mask_2 - {upd_n_result_2.raw_result}')
  15. upd_amp_result_2 = collection_prisma.update_many({'cluster': 2}, {"$set": binary_amp_mask_2[str(date_)]})
  16. print(f'Added amp_mask_2 - {upd_amp_result_2.raw_result}')
  17. if __name__ == '__main__':
  18. date_time_start = datetime.date(2021, 12, 1) # посмотреть почему не собирается конец дня 2018-04-22
  19. date_time_stop = datetime.date(2021, 12, 31)
  20. binary_n_mask_1, binary_amp_mask_1, binary_n_mask_2, binary_amp_mask_2 = sqlmask_converter(date_time_start,
  21. date_time_stop)
  22. LIST_OF_DATES = [(date_time_start + datetime.timedelta(days=i)) for i in
  23. range((date_time_stop - date_time_start).days + 1)]
  24. for date in LIST_OF_DATES:
  25. update_with_add_mask(date, binary_n_mask_1, binary_amp_mask_1, binary_n_mask_2, binary_amp_mask_2)
  26. print('test')