public void UpdateFromRow (ActivityDataRow p_row) { Dictionary<ActivityDataRow.DataType, double> data = (Dictionary<ActivityDataRow.DataType, double>)p_row.data; this.Sport_ID = (uint)p_row.mode; this.ActivitySteps = (uint)data[ActivityDataRow.DataType.DATA_COL_STEP]; this.ActivityDistance = (uint)data[ActivityDataRow.DataType.DATA_COL_DIST]; this.ActivityCalories = (uint)data[ActivityDataRow.DataType.DATA_COL_CALS]; this.ActivityHeart = (uint)data[ActivityDataRow.DataType.DATA_COL_HR]; //~~~update time DateTime today = KreyosUtils.NowWith(p_row.hour, p_row.minute); this.CreatedTime = KreyosUtils.EpochFrom(today); this.CreatedDate = KreyosUtils.DateStringWithYear(today); }
private ActivityDataDoc LoadData(DataReader reader) { //read signature int signature = reader.ReadInt32(); //read head ActivityDataDoc ret = new ActivityDataDoc(); ret.version = (int)reader.ReadByte(); ret.year = (int)reader.ReadByte(); ret.month = (int)reader.ReadByte(); ret.day = (int)reader.ReadByte(); //read data while (reader.UnconsumedBufferLength > 0) { var row = new ActivityDataRow(); //row head row.mode = reader.ReadByte(); row.hour = reader.ReadByte(); row.minute = reader.ReadByte(); //row meta int size = (int)reader.ReadByte(); byte[] meta = new byte[4]; reader.ReadBytes(meta); //row data for (int i = 0, j = 0; meta[i] != 0 && i < 4 && j < size; ++i) { int lvalue = meta[i] >> 4; int rvalue = meta[i] & 0x0f; if (j < size) { int rawValue = reader.ReadInt32(); ActivityDataRow.DataType dtype = dataTypeMap[lvalue]; double value = GetValue(rawValue, dtype); row.data.Add(dtype, value); j++; } if (j < size) { int rawValue = reader.ReadInt32(); ActivityDataRow.DataType dtype = dataTypeMap[rvalue]; double value = GetValue(rawValue, dtype); row.data.Add(dtype, value); j++; } } ret.data.Add(row); } return ret; }
public ActivityDataDoc LoadDataFromBuffer(byte[] buffer) { hexdump(buffer); ActivityDataDoc ret = new ActivityDataDoc(); ret.data = new List<ActivityDataRow>(); int cursor = 4; // jump over signature ret.version = ((int)buffer[cursor++]) & 0x000000ff; ret.year = ((int)buffer[cursor++]) & 0x000000ff; ret.month = ((int)buffer[cursor++]) & 0x000000ff; ret.day = ((int)buffer[cursor++]) & 0x000000ff; while (cursor + 8 < buffer.Length) { ActivityDataRow row = new ActivityDataRow(); row.mode = buffer[cursor++]; row.hour = buffer[cursor++]; row.minute = buffer[cursor++]; row.data = new Dictionary<ActivityDataRow.DataType, double>(); int size = buffer[cursor++]; int[] meta = new int[size]; int meta_cursor = 0; int meta_cnt = 0; for (; meta_cnt < 4 && meta_cursor < size; ++meta_cnt) { int _2d = (int)buffer[cursor + meta_cnt]; _2d = _2d & 0x000000ff; int left = _2d >> 4; int right = _2d & 0x0f; if (left != 0) { meta[meta_cursor++] = left; } else { break; } if (right != 0) { meta[meta_cursor++] = right; } else { break; } } if (meta_cursor != size) { return null; } cursor += 4; for (int i = 0; i < size; ++i) { int dataType = meta[i]; if (cursor + 4 >= buffer.Length) break; int rawValue = bytesToInt(buffer, cursor); double value = 0; switch (dataType) { case (int)ActivityDataRow.DataType.DATA_COL_STEP: case (int)ActivityDataRow.DataType.DATA_COL_CADN: case (int)ActivityDataRow.DataType.DATA_COL_HR: value = rawValue; break; case (int)ActivityDataRow.DataType.DATA_COL_DIST: case (int)ActivityDataRow.DataType.DATA_COL_CALS: value = rawValue % 100; value /= 100.0; value += rawValue / 100; break; } row.data.Add((ActivityDataRow.DataType)dataType, value); cursor += 4; } ret.data.Add(row); } return ret; }
private double GetValue(int rawValue, ActivityDataRow.DataType dtype) { double value = 0; switch (dtype) { case ActivityDataRow.DataType.DATA_COL_STEP: case ActivityDataRow.DataType.DATA_COL_CADN: case ActivityDataRow.DataType.DATA_COL_HR: value = rawValue; break; case ActivityDataRow.DataType.DATA_COL_DIST: case ActivityDataRow.DataType.DATA_COL_CALS: value = rawValue % 100; value /= 100.0; value += rawValue / 100; break; } return value; }