neutron_mask_db_writer.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import datetime
  2. import time
  3. import pandas as pd
  4. import pymongo
  5. from processing_data_prisma import ProccessingPrismaCl
  6. from file_reader.db_file_reader import DbFileReader
  7. def neutron_mask_db_writer(cluster, start_date, end_date, path_to_db):
  8. """Запись нейтронной маски в БД по критерию >0.1 за день."""
  9. for single_date in pd.date_range(start_date, end_date):
  10. db_file_reader = DbFileReader(cluster=cluster, single_date=single_date, db_url=path_to_db)
  11. data_cl = db_file_reader.reading_db()
  12. neutron_to_zero_trigger = ProccessingPrismaCl._neutron_to_zero_trigger(n_file=data_cl)
  13. n_mask_params = [int(val) for val in list(map(lambda x: x < 0.1, neutron_to_zero_trigger))] # Посмотреть
  14. # в каком порядке парсится маска нейтронов, то есть от 1-го до 16-го, или от 16-го до 1-го.
  15. daily_binary_n_mask = {
  16. 'mask_of_hit_counters_n': int(''.join([str(val) for val in n_mask_params]), 2),
  17. 'multiplicity_of_hit_counters_n': sum(n_mask_params)}
  18. collection_prisma = pymongo.MongoClient(path_to_db)["prisma-32_db"][f'{str(single_date.date())}_12d']
  19. upd_n_result = collection_prisma.update_many({'cluster': cluster}, {"$set": daily_binary_n_mask})
  20. print(f'Matched documents n_mask_{cluster} - {upd_n_result.matched_count}')
  21. print(f'Modified documents n_mask_{cluster} - {upd_n_result.modified_count}')
  22. if __name__ == "__main__":
  23. t1 = time.time_ns()
  24. neutron_mask_db_writer(cluster=1, start_date=datetime.date(2018, 2, 1), end_date=datetime.date(2018, 3, 31),
  25. path_to_db="mongodb://localhost:27017/")
  26. neutron_mask_db_writer(cluster=2, start_date=datetime.date(2018, 2, 1), end_date=datetime.date(2018, 3, 31),
  27. path_to_db="mongodb://localhost:27017/")
  28. print(f'time - {(time.time_ns() - t1) / 1e9}')