2 Commits f8d8057120 ... d9a56b180e

Autor SHA1 Mensagem Data
  a7exd d9a56b180e Add '#' to quake id by saving in BulletinStorage 2 anos atrás
  a7exd 8e12261d6a Fix filter quakes by magnitude and obtaining region for quake from DB 2 anos atrás
2 arquivos alterados com 8 adições e 5 exclusões
  1. 1 1
      quake_storages.py
  2. 7 4
      quakes_from_db.py

+ 1 - 1
quake_storages.py

@@ -123,7 +123,7 @@ class BulletinStorage(QuakesStorage):
             _format_to_str(config.STATION_HEADER_DESCRIBE,
                            config.AMNT_COLUMN_SYMBOLS['sta_hdr'])
         sta_strings = self._get_stations_string(quake)
-        return (quake.id, quake_hdr_describe, quake_hdr,
+        return ('#' + quake.id, quake_hdr_describe, quake_hdr,
                 sta_hdr_describe, sta_strings)
 
     def _get_quake_hdr_describe(self) -> str:

+ 7 - 4
quakes_from_db.py

@@ -33,7 +33,7 @@ def _get_sql_query(params: QueryParams) -> str:
            f" o.EVENTID, o.ORIGINTIME, ROUND(o.LAT, 2), ROUND(o.LON, 2)," \
            f" o.`DEPTH`," \
            f" CONCAT(SUBSTR(o.COMMENTS, 1, INSTR(o.COMMENTS, '.') - 3),"\
-           f"        SUBSTR(o.COMMENTS, 20))," \
+           f"        SUBSTR(o.COMMENTS, INSTR(o.COMMENTS, ':') + 4))," \
            f" a.ITIME, a.STA, ROUND(a.DIST, 2)," \
            f" ROUND(a.AZIMUTH, 2), a.IPHASE, CONCAT(a.IM_EM, a.FM)," \
            f" ROUND(a.AMPL, 4), ROUND(a.PER, 2)," \
@@ -131,9 +131,12 @@ def _filter_stations(stations: List[Sta]) -> List[Sta]:
 def _filter_quakes(quakes: List[Quake], params: QueryParams) -> List[Quake]:
     sta_set = set(params.sta.split())
     from_mag, to_mag = float(params.from_mag), float(params.to_mag)
-    res = [quake for quake in quakes
-           if ((from_mag <= quake.magnitude.ML <= to_mag)
-               or (from_mag <= quake.magnitude.MPSP <= to_mag))]
+    res: List[Quake] = []
+    for quake in quakes:
+        mag_ml, mag_mpsp = quake.magnitude
+        mag = mag_ml if mag_ml != 0.0 else mag_mpsp
+        if from_mag <= mag <= to_mag:
+            res.append(quake)
     if params.sta.lower() != 'all':
         res = [quake for quake in res
                if sta_set.issubset(quake.stations_name)]