{"id":16288051,"url":"https://github.com/ingen084/kyoshinmonitorlib","last_synced_at":"2025-03-20T03:30:34.364Z","repository":{"id":18918662,"uuid":"85573185","full_name":"ingen084/KyoshinMonitorLib","owner":"ingen084","description":".NETから簡単に強震モニタを利用できるようにするライブラリ","archived":false,"fork":false,"pushed_at":"2024-11-16T06:55:28.000Z","size":292,"stargazers_count":32,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-17T14:01:56.641Z","etag":null,"topics":["earthquakes","kyoshin-monitor","library"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ingen084.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-03-20T12:16:45.000Z","updated_at":"2025-02-28T09:29:25.000Z","dependencies_parsed_at":"2023-12-02T20:24:50.794Z","dependency_job_id":"6252ee2a-5691-4d0b-b6ef-f14b85f2e6d5","html_url":"https://github.com/ingen084/KyoshinMonitorLib","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ingen084%2FKyoshinMonitorLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ingen084%2FKyoshinMonitorLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ingen084%2FKyoshinMonitorLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ingen084%2FKyoshinMonitorLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ingen084","download_url":"https://codeload.github.com/ingen084/KyoshinMonitorLib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244543702,"owners_count":20469545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["earthquakes","kyoshin-monitor","library"],"created_at":"2024-10-10T19:47:08.393Z","updated_at":"2025-03-20T03:30:33.802Z","avatar_url":"https://github.com/ingen084.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KyoshinMonitorLib\n.NETから簡単に強震モニタを利用できるようにするライブラリ\n\n主に個人用に開発したライブラリです。  \n強震モニタを使用したソフトを開発する際に毎回クラスや処理をコピーするのが面倒なので作成しました。\n\n# 更新情報\n## 0.4.1.0\n### 変更\n\n- 画像解析時に実際の値とずれてしまう問題を修正しました。\n\n## 0.4.0.0\n### 変更\n\n- 画像解析周りの機能を一新しました！\n- 解析アルゴリズムは [こちらの記事(JQuake)](https://qiita.com/NoneType1/items/a4d2cf932e20b56ca444) のものを使用しています。\n\n## 過去の更新情報\n\n- [0.3.x台](https://github.com/ingen084/KyoshinMonitorLib/blob/f635df256afc1a8b772f932818ab6276fe884202/README.md)\n- [0.1.x台](https://github.com/ingen084/KyoshinMonitorLib/blob/e581e49192417d9b65a5403681b8507073c66349/README.md)\n\n# リファレンス\nバージョン:`0.4.0.0`  \n主要なクラスのみ解説します。詳細な解説はソースなどを参照してください。  \nまた、気象庁震度階級や地球の緯度経度など、小学生レベルの前提知識が必要なものがあります。\n\n## KyoshinMonitorExceptionクラス\n強震モニタのAPIから情報を取得している間に、タイムアウトやレスポンスの異常などが確認された場合に発生する例外です。\n### プロパティ\n| 型 | 名前 | 解説 |\n|---|---|---|\n|`string`|Message|どのような例外が発生したか|\n|`Exception`|InnerException|内部で発生した例外|\n\n## ApiResultクラス\nAPIなどを呼んだ際の結果が含まれています。\n### プロパティ\n| 型 | 名前 | 解説 |\n|---|---|---|\n|`HttpStatusCode`|StatusCode|HTTPステータスコード|\n|`TResult`(ジェネリック)|Data|APIの結果 リクエストに失敗した場合`null`の可能性もあります。|\n\n## ObservationPointクラス\n[KyoshinShindoPlaceEditor](https://github.com/ingen084/KyoshinShindoPlaceEditor)と互換があります。\n### LoadFromMpk/Json\n```c#\npublic static ObservationPoint[] LoadFromMpk(string path, bool usingLz4 = false);\npublic static ObservationPoint[] LoadFromJson(string path);\n```\n観測点情報をmpk/jsonから読み込みます。失敗した場合は例外がスローされます。  \n**lz4圧縮済みのmpkを通常のmpkとして読み込まないように注意してください。**\n\n### LoadFromCsv\n```c#\npublic static (ObservationPoint[] points, uint success, uint error) LoadFromCsv(string path, Encoding encoding = null);\n```\n観測点情報をcsvから読み込みます。失敗した場合は例外がスローされます。\n\n### SaveToCsv/Mpk/Json\n```c#\npublic static void SaveToCsv(string path, IEnumerable\u003cObservationPoint\u003e points);\npublic static void SaveToMpk(string path, IEnumerable\u003cObservationPoint\u003e points, bool useLz4 = false);\npublic static void SaveToJson(string path, IEnumerable\u003cObservationPoint\u003e points);\n```\n拡張メソッド版\n```c#\npublic static void SaveToCsv(this IEnumerable\u003cObservationPoint\u003e points, string path);\npublic static void SaveToMpk(this IEnumerable\u003cObservationPoint\u003e points, string path, bool useLz4 = false);\npublic static void SaveToJson(this IEnumerable\u003cObservationPoint\u003e points, string path);\n```\n観測点情報を各形式に保存します。失敗した場合は例外がスローされます。\n\n## Apiクラス共通\n`WebApi`/`AppApi`共通で利用できます。\n### プロパティ\n| 型 | 名前 | 解説 |\n|---|---|---|\n|`TimeSpan`|Timeout|APIを呼ぶにあたってのタイムアウト時間|\n\n## WebApiクラス\nWebで見ることができる強震モニタのAPIを使用してEEWなどの画像やデータを取得するためのクラスです。\n### メソッド\n| 返り値の型 | 名前(引数) | 解説 |\n|---|---|---|\n|`Task\u003cApiResult\u003cEew\u003e\u003e`|GetEewInfo(`DateTime` time)|緊急地震速報のJsonを取得します。  EewクラスはJsonをそのままパースしたものです。 |\n|`Task\u003cApiResult\u003cbyte[]\u003e\u003e`|GetRealtimeImageData(`DateTime` time, `RealtimeDataType` dataType, `bool` isBehore = false)|リアルタイムな情報(リアルタイム･震度･加速度など)の画像のbyte配列を取得します。  画像解析まで行いたい場合は下記の拡張メソッドをご利用ください。|\n|`Task\u003cApiResult\u003cbyte[]\u003e\u003e`|GetEstShindoImageData(`DateTime` time)|緊急地震速報の予想震度の画像のbyte配列を取得します。|\n|`Task\u003cApiResult\u003cbyte[]\u003e\u003e`|GetPSWaveImageData(`DateTime` time)|緊急地震速報のP波とS波の広がりを示す円の画像のbyte配列を取得します。|\n\n### KyoshinMonitorLib.Imagesによる拡張メソッド\n| 返り値の型 | 名前(引数) | 解説 |\n|---|---|---|\n|`Task\u003cApiResult\u003cIEnumerable\u003cImageAnalysisResult\u003e\u003e\u003e`|ParseScaleFromParameterAsync(this `WebApi` webApi, `IEnumerable\u003cObservationPoint\u003e` points, `DateTime` datetime, `RealtimeDataType` dataType = RealtimeDataType.Shindo, `bool` isBehole = false)|ObservationPointのコレクションを使用して新強震モニタの画像を取得し、解析します。|\n\n他にもありますが割愛させていただきます。\n\n#### 画像から震度を解析するにあたってのメモ\n\n`ImageAnalysisResult.AnalysisResult` は強震モニタ上のスケール(0～1)が返されます。  \n解析する画像の種類に応じて `GetResultToIntensity` `GetResultToPga` `GetResultToPgv` `GetResultToPgd` を使い分けてください。\n\n## AppApiクラス\nスマートフォンアプリケーションのAPIを使用してリアルタイム震度などのデータを取得します。  \n**ほとんどのAPIが現在利用できません。** いつか復活を願って処理は残しておきます…。\n### メソッド\n| 返り値の型 | 名前(引数) | 解説 |\n|---|---|---|\n|`Task\u003cApiResult\u003cLinkedRealtimeData[]\u003e\u003e`|GetLinkedRealtimeData(`DateTime` time, `RealtimeDataType` dataType, `bool` isBehore = false)|リアルタイムデータを取得します。  自動で観測点情報などと結びつけ、インスタンスを返します。|\n|`Task\u003cApiResult\u003cRealtimeData\u003e\u003e`|GetRealtimeData(`DateTime` time, `RealtimeDataType` dataType, `bool` isBehore = false)|リアルタイムデータを取得します。  特に理由がない限り`GetLinkedRealtimeData`を使用することを推奨します。|\n|`Task\u003cApiResult\u003cSiteList\u003e\u003e`|GetSiteList(`string` baseSerialNo)|APIから参照できる観測点情報の一覧を取得します。  特に理由がない限り`GetLinkedRealtimeData`を使用することを推奨します。|\n|`Task\u003cApiResult\u003cHypo\u003e\u003e`|GetEewHypoInfo(`DateTime` time)|**[利用不可]** APIから緊急地震速報の情報を取得します。  **ちなみに、複数のEEWに対応してそうです…(要検証)**|\n|`Task\u003cApiResult\u003cPSWave\u003e\u003e`|GetPSWave(`DateTime` time)|**[利用不可]** 緊急地震速報から算出された揺れの広がりを取得します。  **こちらも複数のEEWに対応してそうです。**|\n|`Task\u003cApiResult\u003cEstShindo\u003e\u003e`|GetEstShindo(`DateTime` time)|**[利用不可]** 緊急地震速報から算出された予想震度の5kmメッシュ情報を取得します。|\n|`Task\u003cApiResult\u003cMesh[]\u003e\u003e`|GetMeshes()|**[利用不可]** メッシュ一覧を取得します。 非常に時間がかかるため、起動時などに行い、別ファイルとしてキャッシュしておくことを推奨します。|\n\n### 重要事項\n- `GetEewHypoInfo`\n- `GetPSWave`\n- `GetEstShindo`\n\n**この3つのAPIはEEWが発表されていない場合は404が帰ってきます。**\n\n## Meshクラス\n5kmメッシュ情報を取り扱います。\n### プロパティ\n| 型 | 名前(引数) | 解説 |\n|---|---|---|\n|`string`|Code|メッシュのコード 詳細不明|\n|`Location`|LocationLeftTop|右上(北西)の緯度経度|\n|`Location`|LocationRightBottom|左下(南東)の緯度経度|\n\n### 備考\n使用方法の詳細は省略しますが、 `GetEstShindo` の返り値を見ればわかると思います。  \nですが需要があれば書くかもしれません。またお知らせください。\n\n\n## UrlGeneratorクラス群\nUrlGeneratorは分離した上に、各種Apiクラスでラップしているため、解説は省略させていただきます。\n\n## SecondBasedTimerクラス\nFixedTimerに時刻管理機能をつけたものです。  \n強震モニタの取得タイマーとしてしか考慮していないので必ず1秒になります。\n\n### 注意\n時間の更新(補正)は自動でされないため、別途タイマーなどで実行してください。\n\n### サンプル\n```c#\n//タイマーのインスタンスを作成(デフォルトは精度1ms↓)\nvar timer = new SecondBasedTimer()\n{\n\tOffset = TimeSpan.FromSeconds(2.5), //イベントの発火時間を2500ms *後ろに* ずらす。だいたいこれ前後がおすすめ。\n};\n//適当にイベント設定\ntimer.Elapsed += time =\u003e\n{\n\t//timeに時間が入っているのでそれを使用して取得する\n};\n//タイマー開始 引数には現在の時刻が必要です。\ntimer.Start(await NtpAssistance.GetNetworkTimeWithNtp() ?? throw new Exception());\n\n// 時刻の補正(別のタイマーとかで回すといいと思います)\n//timer.UpdateTime(await NtpAssistance.GetNetworkTimeWithNtp() ?? throw new Exception());\n\n//改行入力待ち\nConsole.ReadLine();\n//タイマーストップ\ntimer.Stop();\n```\n\n## NtpAssistance\nNTPから簡単に時刻取得をするクラスです。\n\n### メソッド\n| 返り値の型 | 名前(引数) | 解説 |\n|---|---|---|\n|`Task\u003cDateTime?\u003e`|GetNetworkTimeWithNtp(`string` hostName = \"ntp.nict.jp\", `ushort` port = 123, `int` timeout = 100)|SNTP通信を使用してネットワーク上から時刻を取得します。  一応SNTPを実装していますが、NICT以外のNTPサーバーでの挙動は保証しません。|\n|`Task\u003cDateTime?\u003e`|GetNetworkTimeWithHttp(`string` url = \"https://ntp-a1.nict.go.jp/cgi-bin/jst\", `double` timeout = 1000)|Http通信を使用してネットワーク上から時刻を取得します。  小数のPOSIX Timeを含んだレスポンスが返されるURLであればなんでも使用できるとおもいます。|\n\n## JmaIntensity\n気象庁震度階級を示す列挙型です。震度異常などを扱うために値が増やされています。\n\n### サンプル\n```c#\nJmaIntensity shindo = 1.0f.ToJmaIntensity(); //JmaIntensity.Int1\nConsole.WriteLine(shindo.ToShortString()); //1\nConsole.WriteLine(shondo.ToLongString()); //震度1\n\nConsole.WriteLine(\"5+\".ToJmaIntensity().ToLongString()); //文字からも解析できます。 出力:震度5強\n\nfloat? invalidIntensity = null;\nConsole.WriteLine(invalidIntensity.ToJmaIntensity()); //nullableなfloatもできます。 出力:JmaIntensity.Unknown\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fingen084%2Fkyoshinmonitorlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fingen084%2Fkyoshinmonitorlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fingen084%2Fkyoshinmonitorlib/lists"}