Merge pull request #237 from bobbycar-graz/more-statistics
This commit is contained in:
@ -126,6 +126,18 @@ class EfficiencyText : public virtual espgui::TextInterface {
|
||||
}
|
||||
};
|
||||
|
||||
class AverageSpeedKmhOverTime : public virtual espgui::TextInterface {
|
||||
public: std::string text() const override {
|
||||
return fmt::format("Avg speed: {:.1f} km/h", getAvgKmh());
|
||||
}
|
||||
};
|
||||
|
||||
class EstimatedKmLeft : public virtual espgui::TextInterface {
|
||||
public: std::string text() const override {
|
||||
return fmt::format("est km:{}", getRemainingEstimateRangeString());
|
||||
}
|
||||
};
|
||||
|
||||
class EfficiencyTextColor : public virtual espgui::ColorInterface {
|
||||
public:
|
||||
int color() const override
|
||||
@ -165,11 +177,13 @@ StatisticsMenu::StatisticsMenu()
|
||||
constructMenuItem<makeComponent<MenuItem, CurrentKilometersText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, CurrentDrivingTimeText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, TotalKilometersText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, TotalMetersText, DummyAction>>();
|
||||
// constructMenuItem<makeComponent<MenuItem, SavedTotalCentimetersText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, CurrentWhUsedText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, AverageWhUsedText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, AverageSpeedKmhOverTime, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, EstimatedKmLeft, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, EfficiencyText, EfficiencyTextColor, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, TotalMetersText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_STATSSAVE>, SaveKilometersAction, StaticMenuItemIcon<&bobbyicons::update>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_STATSCLEAR>, ClearCurrentStatsAction, StaticMenuItemIcon<&bobbyicons::reboot>>>();
|
||||
|
@ -19,6 +19,16 @@ float getAvgWhPerKm()
|
||||
return drivingStatistics.wh_used / (drivingStatistics.meters_driven / 1000.f);
|
||||
}
|
||||
|
||||
float getAvgKmh()
|
||||
{
|
||||
return (drivingStatistics.meters_driven / 1000.) / (drivingStatistics.currentDrivingTime.count() / 1000 / 60 / 60); // (meter / 1000) / (ms / 1000 / 60 / 60)
|
||||
}
|
||||
|
||||
float getEstimatedKmLeft()
|
||||
{
|
||||
return (getRemainingWattHours() / getAvgWhPerKm());
|
||||
}
|
||||
|
||||
std::string getEfficiencyClassString()
|
||||
{
|
||||
const float avgWhPerKm = getAvgWhPerKm();
|
||||
@ -49,6 +59,12 @@ uint16_t getEfficiencyClassColor()
|
||||
else return 0xF800;
|
||||
}
|
||||
|
||||
std::string getRemainingEstimateRangeString()
|
||||
{
|
||||
return fmt::format("{:.1f} km", getEstimatedKmLeft());
|
||||
}
|
||||
|
||||
|
||||
void initStatistics()
|
||||
{
|
||||
|
||||
|
@ -19,5 +19,8 @@ extern DrivingStatistics drivingStatistics;
|
||||
void initStatistics();
|
||||
void calculateStatistics();
|
||||
float getAvgWhPerKm();
|
||||
float getAvgKmh();
|
||||
float getEstimatedKmLeft();
|
||||
std::string getEfficiencyClassString();
|
||||
std::string getRemainingEstimateRangeString();
|
||||
uint16_t getEfficiencyClassColor();
|
||||
|
Reference in New Issue
Block a user