Skip to content

Commit

Permalink
feat: add markets_by_waypoint_type.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Mar 21, 2024
1 parent 28908ea commit e8bce14
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions packages/cli/bin/markets_by_waypoint_type.dart
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);
}

0 comments on commit e8bce14

Please sign in to comment.