|
| 1 | +from .qzss_dcr_decoder_base import QzssDcrDecoderBase |
| 2 | +from .qzss_dcr_decoder_jma_earthquake_early_warning import QzssDcrDecoderJmaEarthquakeEarlyWarning |
| 3 | +from .qzss_dcr_decoder_jma_seismic_intensity import QzssDcrDecoderJmaSeismicIntensity |
| 4 | +from .qzss_dcr_decoder_jma_hypocenter import QzssDcrDecoderJmaHypocenter |
| 5 | +from .qzss_dcr_decoder_jma_tsunami import QzssDcrDecoderJmaTsunami |
| 6 | +from .qzss_dcr_decoder_jma_northwest_pacific_tsunami import QzssDcrDecoderJmaNorthwestPacificTsunami |
| 7 | +from .qzss_dcr_decoder_jma_volcano import QzssDcrDecoderJmaVolcano |
| 8 | +from .qzss_dcr_decoder_jma_ash_fall import QzssDcrDecoderJmaAshFall |
| 9 | +from .qzss_dcr_decoder_jma_weather import QzssDcrDecoderJmaWeather |
| 10 | +from .qzss_dcr_decoder_jma_flood import QzssDcrDecoderJmaFlood |
| 11 | +from .qzss_dcr_decoder_jma_typhoon import QzssDcrDecoderJmaTyphoon |
| 12 | +from .qzss_dcr_decoder_jma_marine import QzssDcrDecoderJmaMarine |
| 13 | +from qzss_dcr_lib.report import QzssDcReportMessageBase |
| 14 | +from qzss_dcr_lib.exception import QzssDcrDecoderException |
| 15 | +from qzss_dcr_lib.definition import qzss_dcr_jma_disaster_category |
| 16 | +from qzss_dcr_lib.definition import qzss_dcr_jma_disaster_category_en |
| 17 | +from qzss_dcr_lib.definition import qzss_dcr_jma_information_type |
| 18 | +from qzss_dcr_lib.definition import qzss_dcr_jma_information_type_en |
| 19 | +from datetime import datetime |
| 20 | + |
| 21 | + |
| 22 | +class QzssDcrDecoderJma(QzssDcrDecoderBase): |
| 23 | + schema = QzssDcReportMessageBase |
| 24 | + |
| 25 | + def decode(self): |
| 26 | + self.version = self.extract_field(214, 6) |
| 27 | + if self.version != 1: |
| 28 | + raise QzssDcrDecoderException( |
| 29 | + f'Unsupported JMA-DC Report Version: {self.version}', |
| 30 | + self.sentence) |
| 31 | + |
| 32 | + dc = self.extract_field(17, 4) |
| 33 | + try: |
| 34 | + self.disaster_category = qzss_dcr_jma_disaster_category[dc] |
| 35 | + self.disaster_category_en = qzss_dcr_jma_disaster_category_en[dc] |
| 36 | + except: |
| 37 | + raise QzssDcrDecoderException( |
| 38 | + f'Undefined Disaster Category: {dc}', |
| 39 | + self.sentence) |
| 40 | + self.disaster_category_no = dc |
| 41 | + |
| 42 | + at_mo = self.extract_field(21, 4) |
| 43 | + if at_mo < 1 or at_mo > 12: |
| 44 | + raise QzssDcrDecoderException( |
| 45 | + f'Invalid Report Time: {at_mo} as month', |
| 46 | + self.sentence) |
| 47 | + at_d = self.extract_field(25, 5) |
| 48 | + if at_d < 1 or at_d > 31: |
| 49 | + raise QzssDcrDecoderException( |
| 50 | + f'Invalid Report Time: {at_d} as day', |
| 51 | + self.sentence) |
| 52 | + at_h = self.extract_field(30, 5) |
| 53 | + if at_h > 23: |
| 54 | + raise QzssDcrDecoderException( |
| 55 | + f'Invalid Report Time: {at_h} as hour', |
| 56 | + self.sentence) |
| 57 | + at_mi = self.extract_field(35, 6) |
| 58 | + if at_mi > 59: |
| 59 | + raise QzssDcrDecoderException( |
| 60 | + f'Invalid Report Time: {at_mi} as minute', |
| 61 | + self.sentence) |
| 62 | + |
| 63 | + at_y = self.now.year |
| 64 | + if at_mo - self.now.month > 6: |
| 65 | + at_y -= 1 |
| 66 | + elif self.now.month - at_mo > 6: |
| 67 | + at_y += 1 |
| 68 | + |
| 69 | + if at_mo == 2 and at_d == 29: |
| 70 | + while at_y % 4 != 0 or (at_y % 100 == 0 and at_y % 400 != 0): |
| 71 | + at_y += 1 |
| 72 | + |
| 73 | + self.report_time = datetime(year=at_y, |
| 74 | + month=at_mo, |
| 75 | + day=at_d, |
| 76 | + hour=at_h, |
| 77 | + minute=at_mi) |
| 78 | + |
| 79 | + it = self.extract_field(41, 2) |
| 80 | + try: |
| 81 | + self.information_type = qzss_dcr_jma_information_type[it] |
| 82 | + self.information_type_en = qzss_dcr_jma_information_type_en[it] |
| 83 | + except: |
| 84 | + raise QzssDcrDecoderException( |
| 85 | + 'Undefined Information Type: {it}', |
| 86 | + self.sentence) |
| 87 | + self.information_type_no = it |
| 88 | + |
| 89 | + if dc == 1: |
| 90 | + next_decoder = QzssDcrDecoderJmaEarthquakeEarlyWarning |
| 91 | + elif dc == 2: |
| 92 | + next_decoder = QzssDcrDecoderJmaHypocenter |
| 93 | + elif dc == 3: |
| 94 | + next_decoder = QzssDcrDecoderJmaSeismicIntensity |
| 95 | + elif dc == 4: |
| 96 | + raise QzssDcrDecoderException( |
| 97 | + 'Decoder Not Implemented: JMA Nankai Trough Earthquake Information', |
| 98 | + self.sentence) |
| 99 | + elif dc == 5: |
| 100 | + next_decoder = QzssDcrDecoderJmaTsunami |
| 101 | + elif dc == 6: |
| 102 | + next_decoder = QzssDcrDecoderJmaNorthwestPacificTsunami |
| 103 | + elif dc == 8: |
| 104 | + next_decoder = QzssDcrDecoderJmaVolcano |
| 105 | + elif dc == 9: |
| 106 | + next_decoder = QzssDcrDecoderJmaAshFall |
| 107 | + elif dc == 10: |
| 108 | + next_decoder = QzssDcrDecoderJmaWeather |
| 109 | + elif dc == 11: |
| 110 | + next_decoder = QzssDcrDecoderJmaFlood |
| 111 | + elif dc == 12: |
| 112 | + next_decoder = QzssDcrDecoderJmaTyphoon |
| 113 | + elif dc == 14: |
| 114 | + next_decoder = QzssDcrDecoderJmaMarine |
| 115 | + else: |
| 116 | + raise QzssDcrDecoderException( |
| 117 | + f'Unsupported Disaster Category: {self.disaster_category}', |
| 118 | + self.sentence) |
| 119 | + |
| 120 | + return next_decoder(**self.get_params()).decode() |
0 commit comments