Parcourir la source

add def(n7 conventer)

acoustic925 il y a 2 ans
Parent
commit
fe6be1f132
3 fichiers modifiés avec 33 ajouts et 11 suppressions
  1. 29 7
      file_reader/file_reader.py
  2. 1 1
      noSQL_db_Prisma.py
  3. 3 3
      runner.py

+ 29 - 7
file_reader/file_reader.py

@@ -55,13 +55,23 @@ class FileReader:
 
     def reading_n7_file(self):
         print(self.n7_file_path)
-        n7_file = pd.read_csv(self.n7_file_path,
-                              sep=r'\s[-]*\s*', header=None, skipinitialspace=True, index_col=False, engine='python')
-        n7_file.dropna(axis=1, how='all', inplace=True)
-        n7_file[0] = n7_file[0].apply(lambda x: str(x).replace(',', '.')) # add this rows to file-twink
-        n7_file = n7_file.astype({0: float})
-        n7_file = n7_file[n7_file[0] < 86400]
-        time_difference = n7_file[0].diff()
+        try:
+            n7_file = pd.read_csv(self.n7_file_path,
+                                  sep=r'\s[-]*\s*', header=None, skipinitialspace=True, index_col=False,
+                                  engine='python')
+            n7_file.dropna(axis=1, how='all', inplace=True)
+            n7_file.columns = ['time', 'number', 'trigger'] + [f'amp{i}' for i in range(1, 17)]
+        except ValueError:
+            self.n7_file_conventer()
+            n7_file = pd.read_csv(self.n7_file_path,
+                                  sep=r'\s[-]*\s*', header=None, skipinitialspace=True, index_col=False,
+                                  engine='python')
+            n7_file.dropna(axis=1, how='all', inplace=True)
+            n7_file.columns = ['time', 'number', 'trigger'] + [f'amp{i}' for i in range(1, 17)]
+        n7_file['time'] = n7_file['time'].apply(lambda x: str(x).replace(',', '.'))  # add this rows to file-twink
+        n7_file = n7_file.astype({'time': float})
+        n7_file = n7_file[n7_file['time'] < 86400]
+        time_difference = n7_file['time'].diff()
         bad_end_time_index = time_difference[time_difference < -10000].index
         if any(bad_end_time_index):
             n7_file_today = n7_file[n7_file.index < bad_end_time_index[0]]
@@ -123,6 +133,18 @@ class FileReader:
         t_file_df = t_file_df[t_file_df["time"] < 86400]
         return t_file_df
 
+    def n7_file_conventer(self):
+        with open(self.n7_file_path, 'r') as f:
+            raw_data = f.readlines()
+        if len(list(filter(lambda x: x != '', raw_data[0].rstrip().split(' ')))) < 5:
+            start_of_strings = [line.rstrip() for line in raw_data[::2]]
+            end_of_strings = raw_data[1::2]
+            raw_data = [x + ' ' + y for x, y in zip(start_of_strings, end_of_strings)]
+            with open(self.n7_file_path, 'w') as f:
+                f.writelines(raw_data)
+        else:
+            raise FileNotFoundError
+
     def reading_p_file(self):
         """Метод, прочитывающий p-файлы, возвращающий датафрейм дня на выходе. Или возвращающий filenotfounderror, если
         файла нет"""

+ 1 - 1
noSQL_db_Prisma.py

@@ -19,7 +19,7 @@ class NoSQLPrisma:
         self.cluster = cluster
         self.single_date = single_date
         self.file_reader = FileReader(cluster=self.cluster, single_date=self.single_date,
-                                      path_to_files=f'z:\\PRISMA-32\\DataArchive\\P{self.cluster}\\data{self.single_date.year}')
+                                      path_to_files=f'z:\\PRISMA-32\\DataArchive\\DATA P{self.cluster} archive\\data{self.single_date.year}')
 
     # def __del__(self):
     #     pass

+ 3 - 3
runner.py

@@ -2,9 +2,9 @@ import datetime
 from noSQL_db_Prisma import NoSQLPrisma
 
 
-date_time_start = datetime.date(2022, 9, 14)  # посмотреть почему не собирается конец дня 2018-04-22
-# date_time_stop = datetime.date(2020, 10, 28)
-date_time_stop = datetime.date.today()
+date_time_start = datetime.date(2022, 9, 29)  # посмотреть почему не собирается конец дня 2018-04-22
+date_time_stop = datetime.date(2022, 9, 29)
+# date_time_stop = datetime.date.today()
 LIST_OF_DATES = [(date_time_start + datetime.timedelta(days=i)) for i in
                  range((date_time_stop - date_time_start).days + 1)]
 for date in LIST_OF_DATES: