void recordType(TypeProfileKey key, DataType dt) { if (!profiles) return; if (!isProfileRequest()) return; assert(dt != KindOfUninit); // Normalize strings to KindOfString. if (dt == KindOfStaticString) dt = KindOfString; TRACE(1, "recordType lookup: %s -> %d\n", key.m_name->data(), dt); ValueProfile *prof = keyToVP(key, KeyToVPMode::Write); if (prof->m_totalSamples != kMaxCounter) { prof->m_totalSamples++; // NB: we can't quite assert that we have fewer than kMaxCounter samples, // because other threads are updating this structure without locks. int dtIndex = getDataTypeIndex(dt); if (prof->m_samples[dtIndex] < kMaxCounter) { prof->m_samples[dtIndex]++; } } ONTRACE(2, prof->dump()); }
void DataWarehouse::putData( int16_t data, uint8_t dataType, uint8_t hour ) { uint8_t todayIndex; uint8_t dataTypeIndex; uint8_t hourIndex; todayIndex = eeprom_read_byte((const uint8_t *)STORE_ADDR_TODAYINDEX); dataTypeIndex = getDataTypeIndex(dataType); hourIndex = hour2Index(hour); eeprom_write_byte( (uint8_t *)STORE_ADDR_VALIDFLAG, ~DATA_VALID ); writeData( data, todayIndex, dataTypeIndex, hourIndex ); eeprom_write_byte( (uint8_t *)STORE_ADDR_VALIDFLAG, DATA_VALID ); DBG_PRINT("putData:") DBG_PRINTLN_VAR(dataType, DEC); DBG_PRINTLN_VAR(data, DEC); }
int16_t DataWarehouse::getDayMin( uint8_t dataType, uint8_t daysBeforeToday, uint8_t *p_hour) { uint8_t dayIndex, hourIndex; uint8_t dataTypeIndex; boolean firstFlag; uint8_t minHourIndex; int16_t data; int16_t min; dayIndex = ((eeprom_read_byte((const uint8_t *)STORE_ADDR_TODAYINDEX) + DATA_SAVE_DAYS) - daysBeforeToday) % DATA_SAVE_DAYS; dataTypeIndex = getDataTypeIndex(dataType); firstFlag = false; for ( hourIndex = 0; hourIndex < SAMPLE_TIMES_PERDAY; hourIndex++ ) { data = readData( dayIndex, dataTypeIndex, hourIndex); if ( INVALID_INT16 != data ) { if ( (data < min) || (!firstFlag) ) { minHourIndex = hourIndex; min = data; } firstFlag = true; } } if ( p_hour != NULL ) { *p_hour = index2Hour(minHourIndex); } return ( firstFlag ) ? min : INVALID_INT16; }
//todo, count int16_t DataWarehouse::getDayAverage( uint8_t dataType, uint8_t daysBeforeToday, uint8_t *p_number) { uint8_t dayIndex, hourIndex; uint8_t dataTypeIndex; uint8_t count; int16_t data; int32_t sum; dayIndex = ((eeprom_read_byte((const uint8_t *)STORE_ADDR_TODAYINDEX) + DATA_SAVE_DAYS) - daysBeforeToday) % DATA_SAVE_DAYS; dataTypeIndex = getDataTypeIndex(dataType); count = 0; sum = 0; for ( hourIndex = 0; hourIndex < SAMPLE_TIMES_PERDAY; hourIndex++ ) { data = readData( dayIndex, dataTypeIndex, hourIndex); if ( INVALID_INT16 != data ) { sum += data; count++; } } DBG_PRINTLN_VAR(sum,DEC); DBG_PRINTLN_VAR(count,DEC); if ( NULL != p_number ) { *p_number = count; } return ( 0 == count ) ? INVALID_INT16 : (sum/count); }