badge percentage support
This commit is contained in:
@@ -827,3 +827,85 @@ class BadgeAward {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ClassClearanceProgress {
|
||||
final String className;
|
||||
final int completed;
|
||||
final int total;
|
||||
final double percentComplete;
|
||||
|
||||
ClassClearanceProgress({
|
||||
required this.className,
|
||||
required this.completed,
|
||||
required this.total,
|
||||
required this.percentComplete,
|
||||
});
|
||||
|
||||
factory ClassClearanceProgress.fromJson(Map<String, dynamic> json) {
|
||||
final name = _asString(json['class'] ?? json['class_name'] ?? json['name']);
|
||||
final completed = _asInt(
|
||||
json['completed'] ?? json['done'] ?? json['count'] ?? json['had'],
|
||||
);
|
||||
final total = _asInt(json['total'] ?? json['required'] ?? json['goal']);
|
||||
double percent = _asDouble(
|
||||
json['percent_complete'] ??
|
||||
json['percent'] ??
|
||||
json['completion'] ??
|
||||
json['pct'],
|
||||
);
|
||||
if (percent == 0 && total > 0) {
|
||||
percent = (completed / total) * 100;
|
||||
}
|
||||
return ClassClearanceProgress(
|
||||
className: name.isNotEmpty ? name : 'Class',
|
||||
completed: completed,
|
||||
total: total,
|
||||
percentComplete: percent,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class LocoClearanceProgress {
|
||||
final LocoSummary loco;
|
||||
final double mileage;
|
||||
final double required;
|
||||
final String nextTier;
|
||||
final List<String> awardedTiers;
|
||||
final double percent;
|
||||
|
||||
LocoClearanceProgress({
|
||||
required this.loco,
|
||||
required this.mileage,
|
||||
required this.required,
|
||||
required this.nextTier,
|
||||
required this.awardedTiers,
|
||||
required this.percent,
|
||||
});
|
||||
|
||||
factory LocoClearanceProgress.fromJson(Map<String, dynamic> json) {
|
||||
final locoJson = json['loco'];
|
||||
final loco = locoJson is Map<String, dynamic>
|
||||
? LocoSummary.fromJson(Map<String, dynamic>.from(locoJson))
|
||||
: LocoSummary(
|
||||
locoId: _asInt(json['loco_id']),
|
||||
locoType: _asString(json['loco_type']),
|
||||
locoNumber: _asString(json['loco_number']),
|
||||
locoName: _asString(json['loco_name']),
|
||||
locoClass: _asString(json['loco_class']),
|
||||
locoOperator: _asString(json['operator']),
|
||||
powering: true,
|
||||
locoNotes: null,
|
||||
locoEvn: null,
|
||||
);
|
||||
return LocoClearanceProgress(
|
||||
loco: loco,
|
||||
mileage: _asDouble(json['mileage']),
|
||||
required: _asDouble(json['required']),
|
||||
nextTier: _asString(json['next_tier']),
|
||||
awardedTiers: (json['awarded_tiers'] as List? ?? [])
|
||||
.map((e) => e.toString())
|
||||
.toList(),
|
||||
percent: _asDouble(json['percent']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user