void device_GetSportStatus(DeviceDataManager.SportStatus sportStatus) { Console.WriteLine(sportStatus.HeartRate + " " + sportStatus.load + " " + sportStatus.distance); totalInfo++; TimeSpan time = DateTime.Now - InfoControl.LoginTime; data.Add(new ChartInfo( totalInfo, Convert.ToInt32(time.TotalSeconds), sportStatus.Speed / 6.0 * 5.0, sportStatus.HeartRate, sportStatus.distance, sportStatus.distance * sportStatus.load )); //data.Add(new ChartInfo(-1, 0, 0, 0, 0, 0)); if (data.Count > MAX_POINT) //将以前的数据移出 { bufData.Add(data[0]); data.RemoveAt(0); } if (bufData.Count >= MAX_BUFFER && !isProcessing) { isProcessing = true; //正在进行数据转移 Thread t = new Thread(new ThreadStart(transferDataToFile)); t.Start(); } }
void device_GetSportStatus(DeviceDataManager.SportStatus sportStatus) { if (LearningMode) { double[] input = { (double)DataCount / TrainingCount, (double)sportStatus.Speed / 20, (double)sportStatus.HeartRate / byte.MaxValue, (double)preLoad / byte.MaxValue }; double[] output = { (double)Shift / byte.MaxValue }; Console.WriteLine(sportStatus.load); Console.WriteLine(Shift); preLoad = Shift; inputList[DataCount] = input; outputList[DataCount] = output; DataCount++; if (DataCount == TrainingCount) { LearningMode = false; DataCount = 0; for (int i = 0; i < 5000; i++) { double error = bp.RunEpoch(inputList, outputList); listBox1.Invoke(new Action(() => { listBox1.Items.Add(error); })); } MessageBox.Show("Learning Over"); timer1.Start(); } } else { double[] input = { (double)DataCount / TrainingCount, (double)sportStatus.Speed / byte.MaxValue, /*(double)sportStatus.HeartRate*/ (double)60 / byte.MaxValue, (double)preLoad / byte.MaxValue }; double output = an.Compute(input)[0]; listBox2.Invoke(new Action(() => { listBox2.Items.Add(((int)(output * 255)).ToString()); })); BuzzWin.DeviceDataManager.Damp d = new DeviceDataManager.Damp(); d.value = (int)(output * 255); device.SetDamp(d); DataCount++; } }
void device_GetSportStatus(DeviceDataManager.SportStatus sportStatus) { if (LearningMode) { double[] input = { (double)DataCount / TrainingCount, (double)sportStatus.Speed / 20, (double)sportStatus.HeartRate / byte.MaxValue, (double)preLoad / byte.MaxValue }; double[] output = { (double)Shift / byte.MaxValue }; Console.WriteLine(sportStatus.load); Console.WriteLine(Shift); preLoad = Shift; inputList[DataCount] = input; outputList[DataCount] = output; loadData.Add(new LoadInfo(Shift, DataCount)); //loadData.Add(new LoadInfo(DataCount * 10 + 10, DataCount * 5 + 5)); //this.Dispatcher.Invoke(new Action(() => //{ // loadData.Add(new LoadInfo(2, 5)); // chartLoad.ItemsSource = loadData; // chartLoad.Refresh(); //})); this.Dispatcher.Invoke(new Action(() => { updateChartInfo(loadData); })); DataCount++; if (DataCount == TrainingCount) { LearningMode = false; DataCount = 0; for (int i = 0; i < 5000; i++) { double error = bp.RunEpoch(inputList, outputList); //listBox1.Invoke(new Action(() => //{ // listBox1.Items.Add(error); //})); Console.WriteLine(error); } MessageBox.Show("Learning Over"); } } else { double[] input = { (double)DataCount / TrainingCount, (double)sportStatus.Speed / byte.MaxValue, /*(double)sportStatus.HeartRate*/ (double)60 / byte.MaxValue, (double)preLoad / byte.MaxValue }; double output = an.Compute(input)[0]; //listBox2.Invoke(new Action(() => // { // listBox2.Items.Add(((int)(output * 255)).ToString()); // })); BuzzWin.DeviceDataManager.Damp d = new DeviceDataManager.Damp(); d.value = (int)(output * 255); loadData.Add(new LoadInfo(d.value, DataCount)); while (loadData.Count > MAX_COUNT) { loadData.RemoveAt(0); } this.Dispatcher.Invoke(new Action(() => { updateChartInfo(loadData); })); InfoControl.device.SetDamp(d); DataCount++; } }