Merge pull request #99 from cake-tech/CAKE-291-rescan-restore-from-date-issue

CAKE-291 | fixed bug in the get_height_by_date.dart
This commit is contained in:
M 2021-03-29 21:23:28 +03:00
commit f93d10face

View file

@ -85,28 +85,35 @@ final dates = {
"2020-11": 2220000
};
final heightCoefficient = 0.7;
int getHeigthByDate({DateTime date}) {
final raw = '${date.year}' + '-' + '${date.month}';
final lastHeight = dates.values.last;
int startHeight;
int endHeight;
int height;
int height = 0;
if ((dates[raw] == null)||(dates[raw] == lastHeight)) {
startHeight = dates.values.toList()[dates.length - 2];
endHeight = dates.values.toList()[dates.length - 1];
final heightPerDay = (endHeight - startHeight) / 31;
final daysHeight = (heightCoefficient * (date.day - 1) * heightPerDay).round();
height = endHeight + daysHeight;
} else {
startHeight = dates[raw];
final index = dates.values.toList().indexOf(startHeight);
endHeight = dates.values.toList()[index + 1];
final heightPerDay = ((endHeight - startHeight) / 31).round();
final daysHeight = (date.day - 1) * heightPerDay;
height = startHeight + daysHeight - heightPerDay;
try {
if ((dates[raw] == null)||(dates[raw] == lastHeight)) {
startHeight = dates.values.toList()[dates.length - 2];
endHeight = dates.values.toList()[dates.length - 1];
final heightPerDay = (endHeight - startHeight) / 31;
final endDateRaw = dates.keys.toList()[dates.length - 1].split('-');
final endYear = int.parse(endDateRaw[0]);
final endMonth = int.parse(endDateRaw[1]);
final endDate = DateTime(endYear, endMonth);
final differenceInDays = date.difference(endDate).inDays;
final daysHeight = (differenceInDays * heightPerDay).round();
height = endHeight + daysHeight;
} else {
startHeight = dates[raw];
final index = dates.values.toList().indexOf(startHeight);
endHeight = dates.values.toList()[index + 1];
final heightPerDay = ((endHeight - startHeight) / 31).round();
final daysHeight = (date.day - 1) * heightPerDay;
height = startHeight + daysHeight - heightPerDay;
}
} catch (e) {
print(e.toString());
}
return height;