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