Esempio n. 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // 設定ファイルをロード
            List <string> pointItems = new List <string>();

            using (StreamReader sr = new StreamReader(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "div22.json")))
            {
                JObject jobj = JObject.Parse(sr.ReadToEnd());;

                // pyhton.exeのパス
                pythonExePath = jobj["Python"]["Exe"].ToString();

                // 実行するpythonスクリプトのパス
                pythonScriptPath = jobj["Python"]["Scripy"].ToString();

                // データ蓄積サーバの get_sensor_data のベースUri
                UriGenerator.SetBaseUriGetSensorData(jobj["Uri"]["GetSensorData"].ToString());

                // 地点コンボボックスの初期設定
                for (int i = 0; i < jobj["Point"]["Items"].Count(); i++)
                {
                    comboBoxPointSelect.Items.Add(jobj["Point"]["Items"][i].ToString());
                }
                comboBoxPointSelect.SelectedItem = jobj["Point"]["Initial"].ToString();

                // アルゴリズムコンボボックス、および、正解率配列の初期設定
                accuracyRateArray = new double[jobj["Algorithm"]["Items"]["DisplayName"].Count(), 2];
                for (int i = 0; i < jobj["Algorithm"]["Items"]["DisplayName"].Count(); i++)
                {
                    string key                 = jobj["Algorithm"]["Items"]["DisplayName"][i].ToString();
                    string value               = jobj["Algorithm"]["Items"]["Abbreviation"][i].ToString();
                    double accuracyRate        = double.Parse(jobj["Algorithm"]["Items"]["AccuracyRate"][i].ToString());
                    double accuracyRateNextDay = double.Parse(jobj["Algorithm"]["Items"]["AccuracyRateNextDay"][i].ToString());

                    comboBoxAlgorithmSelect.Items.Add(key);
                    algorithmMap.Add(key, value);

                    // 当日の正解率
                    accuracyRateArray[i, 0] = accuracyRate;

                    // 翌日の正解率
                    accuracyRateArray[i, 1] = accuracyRateNextDay;
                }
                comboBoxAlgorithmSelect.SelectedItem = jobj["Algorithm"]["Initial"].ToString();

                // 正解率配列の初期設定
            }

            // コンボボックスの初期設定
            comboBoxTimeSelect.Items.AddRange(new string[] {
                " 0時",
                " 3時",
                " 6時",
                " 9時",
                "12時",
                "15時",
                "18時",
                "21時"
            }
                                              );
            comboBoxTimeSelect.SelectedIndex = 4;

            // 予想日コンボボックスの初期設定
            comboBoxExpectedDateSelect.Items.AddRange(new string[] {
                "当日",
                "翌日"
            });
            comboBoxExpectedDateSelect.SelectedIndex = 0;

            // 初期化済みフラグを更新
            isInitialized = true;

            // 正解率ラベルの初期化
            updateAccuracyRateLabel();
        }
Esempio n. 2
0
        private void buttonTest_Click(object sender, EventArgs e)
        {
            // サーバに問い合わせて、jsonデータを取得
            string uriGetSensorData = UriGenerator.GenerateGetSensorDataUri(
                dateTimePicker.Value.Year,
                dateTimePicker.Value.Month,
                dateTimePicker.Value.Day,
                comboBoxTimeSelect.SelectedIndex * 3);
            JArray jsonGetSensorData = JArray.Parse(new HttpClient().GetStringAsync(uriGetSensorData).Result);

            // jsonデータが0件の場合、エラーダイアログを表示してなにもしない。
            if (jsonGetSensorData.Count < 1)
            {
                MessageBox.Show("サーバとの通信に失敗したか、指定した日時のデータが存在しません。",
                                "ERROR",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            // サーバから取得したjsonデータを
            File.WriteAllText(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "get_sensor_data.txt"),
                jsonGetSensorData.ToString());

            // DataGridViewにjsonデータを表示
            dataGridView1.Rows.Clear();
            for (int i = 0; i < jsonGetSensorData.Count; i++)
            {
                dataGridView1.Rows.Add(new string[] {
                    jsonGetSensorData[i]["id"].ToString(),
                    jsonGetSensorData[i]["year"].ToString(),
                    jsonGetSensorData[i]["month"].ToString(),
                    jsonGetSensorData[i]["day"].ToString(),
                    jsonGetSensorData[i]["hour"].ToString(),
                    double.Parse(jsonGetSensorData[i]["temperture"].ToString()).ToString("F1"),
                    double.Parse(jsonGetSensorData[i]["humidity"].ToString()).ToString("F1"),
                    double.Parse(jsonGetSensorData[i]["pressure"].ToString()).ToString("F1")
                });
            }

            // 機械学習ツールへ渡すパラメータを作成
            string csvWeatherStr = json2csv(jsonGetSensorData, comboBoxPointSelect.SelectedIndex + 1);

            if (csvWeatherStr == null)
            {
                MessageBox.Show(string.Format("指定した地点(ID: {0})のデータが存在しません。", comboBoxPointSelect.SelectedIndex + 1),
                                "ERROR",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            string pythonArguments = String.Format("{0} \"{1}\" {2} {3} {4}",
                                                   (csvWeatherStr.Length - csvWeatherStr.Replace("|", "").Length + 1),
                                                   csvWeatherStr,
                                                   comboBoxExpectedDateSelect.SelectedItem.ToString(),
                                                   algorithmMap[comboBoxAlgorithmSelect.SelectedItem.ToString()],
                                                   comboBoxPointSelect.SelectedItem.ToString());

            // 機械学習ツールへ渡すパラメータを作成
            // ※これは、機械学習ツールとの連携確認用

            /*
             * string csvWeatherStr = "2011,12,31,3,3.5,37,1018.1|2011,12,31,6,3.2,41,1019.1|2011,12,31,9,3,48,1020.3|2011,12,31,12,8.6,29,1018.2|2011,12,31,15,9.5,24,1017.8|2011,12,31,18,8.2,30,1019.1|2011,12,31,21,5.4,39,1019.5|2012,1,1,3,4.4,41,1018.4";
             * string pythonArguments = String.Format(" {0} {1} {2} {3} {4}",
             *  (csvWeatherStr.Length - csvWeatherStr.Replace("|", "").Length + 1),
             *  csvWeatherStr,
             *  "当日",
             *  "DT",
             *  "東京");
             */

            // Python 実行して、終了まで待機
            Process ps = new Process();

            ps.StartInfo.FileName  = pythonExePath;
            ps.StartInfo.Arguments = string.Join(" ", new string[] { pythonScriptPath, pythonArguments });
            ps.Start();
            ps.WaitForExit();

            // 終了したら、画面に結果を表示
            pictureBoxExpect.Image = GetWeatherBitmap(ps.ExitCode);

            // 正解データを Weather Hacks から取得して表示
            string  uriWeatherHacks  = UriGenerator.GenerateWeatherHacksUri(comboBoxPointSelect.SelectedItem.ToString());
            JObject jsonWeatherHacks = JObject.Parse(new HttpClient().GetStringAsync(uriWeatherHacks).Result);

            pictureBoxActual.Image = GetWeatherBitmap((string)(jsonWeatherHacks["forecasts"][0]["telop"] as JValue).Value);
        }