Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef OVERTIME_H
00018 #define OVERTIME_H OVERTIME_H
00019
00020 #include "Activity.h"
00021
00022 #include <QtCore/QObject>
00023
00024 #include <vector>
00025
00026 int fine(int overtime) {
00027 if(overtime) return (overtime / 30 + 1) * 30;
00028 return 0;
00029 }
00030
00031 void checkDayDrivingTime(dailyActivity& a) {
00032 typedef std::vector<Activity> subray;
00033 typedef subray::const_iterator subiter;
00034 int sincelastbreak = 0;
00035 int overtime = 0;
00036 bool had15minbreak = false;
00037 for(subiter i = a.driver.begin(); i < a.driver.end(); ++i) {
00038 const int& d = i->duration;
00039 if(i->activity == Activity::Driving) {
00040 sincelastbreak += d;
00041 }
00042 if(i->activity == Activity::Break && d >= 15) {
00043 if(d < 30) had15minbreak = true;
00044 else if(d >= 30) {
00045 if(had15minbreak || d >= 45) {
00046 if(sincelastbreak > 270) overtime += sincelastbreak - 270;
00047 sincelastbreak = 0;
00048 had15minbreak = false;
00049 } else had15minbreak = true;
00050 }
00051 }
00052 }
00053 if(sincelastbreak > 270) overtime += sincelastbreak - 270;
00054 a.overtime = std::max(overtime, a.driventime - 600);
00055 a.fine = fine(a.overtime);
00056 if(a.overtime) a.overtimeReason = QObject::tr("Daily driving time");
00057 }
00058
00059 int checkTimes(std::vector<dailyActivityCard>& days) {
00060 int fine = 0;
00061 int weekdays = 0;
00062 int weekdriven = 0;
00063 for(std::vector<dailyActivityCard>::iterator j = days.begin(); j
00064 < days.end(); ++j) {
00065 checkDayDrivingTime(*j);
00066 fine += j->fine;
00067 ++weekdays;
00068 weekdriven += j->driventime;
00069 if((j->start.timestamp % (86400 * 7)) / 86400 == 3) {
00070
00071 j->weekStats = QObject::tr("driven for ") + formatMinutes(weekdriven);
00072 if(weekdays != 7) j->weekStats += " " + QObject::tr("only") + " "
00073 + stringify(weekdays) + " " + QObject::tr("recorded");
00074 weekdriven = 0;
00075 weekdays = 0;
00076 }
00077 }
00078 return fine;
00079 }
00080
00081 #endif