-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add markets_by_waypoint_type.dart
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import 'package:cli/cache/charting_cache.dart'; | ||
import 'package:cli/cache/market_listing_snapshot.dart'; | ||
import 'package:cli/cache/systems_cache.dart'; | ||
import 'package:cli/cli.dart'; | ||
import 'package:cli_table/cli_table.dart'; | ||
|
||
Map<String, dynamic> rightAlign(Object? content) => <String, dynamic>{ | ||
'content': content.toString(), | ||
'hAlign': HorizontalAlign.right, | ||
}; | ||
|
||
Future<void> command(FileSystem fs, Database db, ArgResults argResults) async { | ||
final chartingSnapshot = await ChartingSnapshot.load(db); | ||
final marketListings = await MarketListingSnapshot.load(db); | ||
final systemsCache = SystemsCache.load(fs)!; | ||
|
||
// Walk all charting records. | ||
// Record the number of known waypoints by type. | ||
// Record if it has a market. | ||
final waypointsByType = <WaypointType, int>{}; | ||
final waypointsWithMarket = <WaypointType, int>{}; | ||
for (final record in chartingSnapshot.records) { | ||
final waypoint = systemsCache.waypoint(record.waypointSymbol); | ||
waypointsByType[waypoint.type] = (waypointsByType[waypoint.type] ?? 0) + 1; | ||
if (marketListings[record.waypointSymbol] != null) { | ||
waypointsWithMarket[waypoint.type] = | ||
(waypointsWithMarket[waypoint.type] ?? 0) + 1; | ||
} | ||
} | ||
// Print the results. | ||
final table = Table( | ||
header: ['Waypoint Type', '%', 'Count', 'Markets'], | ||
style: const TableStyle(compact: true), | ||
); | ||
for (final type in waypointsByType.keys) { | ||
final waypointCount = waypointsByType[type]!; | ||
final marketCount = waypointsWithMarket[type] ?? 0; | ||
final percentWithMarket = (marketCount / waypointCount * 100).round(); | ||
table.add([ | ||
type.value, | ||
rightAlign(percentWithMarket), | ||
rightAlign(waypointCount), | ||
rightAlign(marketCount), | ||
]); | ||
} | ||
logger.info(table.toString()); | ||
} | ||
|
||
void main(List<String> args) async { | ||
await runOffline(args, command); | ||
} |