mask_db_delete.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import datetime
  2. import time
  3. import pandas as pd
  4. # import numpy as np
  5. import pymongo
  6. from config_info.config import DB_URL
  7. # from file_reader.db_file_reader import DbFileReader
  8. db_client = pymongo.MongoClient(DB_URL)
  9. prisma_db = db_client["prisma-32_db"]
  10. def mask_db_delete(cluster, start_date, end_date, mask_type):
  11. """Удаление данных нейтронной или амплитудной маски, за выделенный промежуток времени."""
  12. for single_date in pd.date_range(start_date, end_date):
  13. collection_prisma = prisma_db[f'{str(single_date.date())}_12d']
  14. upd_result = collection_prisma.update_many({'cluster': cluster},
  15. {"$unset": {
  16. f'mask_of_hit_counters_{mask_type}': "",
  17. f'multiplicity_of_hit_counters_{mask_type}': ""}})
  18. print(f'Matched documents {mask_type}_mask_{cluster} - {upd_result.matched_count}')
  19. print(f'Modified documents {mask_type}_mask_{cluster} - {upd_result.modified_count}')
  20. if __name__ == "__main__":
  21. t1 = time.time_ns()
  22. mask_db_delete(cluster=1, start_date=datetime.date(2012, 1, 1), end_date=datetime.date(2021, 1, 31),
  23. mask_type='amp')
  24. mask_db_delete(cluster=2, start_date=datetime.date(2012, 1, 1), end_date=datetime.date(2021, 1, 31),
  25. mask_type='amp')
  26. mask_db_delete(cluster=1, start_date=datetime.date(2012, 1, 1), end_date=datetime.date(2021, 1, 31),
  27. mask_type='n')
  28. mask_db_delete(cluster=2, start_date=datetime.date(2012, 1, 1), end_date=datetime.date(2021, 1, 31),
  29. mask_type='n')
  30. print(f'time - {(time.time_ns() - t1) / 1e9}')