Last active
June 17, 2019 22:22
-
-
Save liyuqian/403400fddd0e2a8687dbd6e092f21d51 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Run this by `history > history.out && dart analyze_date.dart`. | |
// Or you can download and run this script by: | |
// ``` | |
// curl https://gist.githubusercontent.com/liyuqian/403400fddd0e2a8687dbd6e092f21d51/raw/analyze_date.dart > analyze_dart.dart && history > history.out && dart analyze_dart.dart | |
// ``` | |
import 'dart:io'; | |
void printAnalysis(String action, Set<String> dates) { | |
final firstDate = DateTime.parse(dates.first); | |
final lastDate = DateTime.parse(dates.last); | |
int totalDays = lastDate.difference(firstDate).inDays + 1; | |
print('Your first day of $action in `history` is ${dates.first}.'); | |
print('Your last day of $action `history` is ${dates.last}.'); | |
print('You have $action in ${dates.length} out of $totalDays days.'); | |
print('That\'s a rate of ${dates.length / totalDays}.'); | |
print(""); | |
} | |
void processLines(List<String> lines) { | |
Set<String> dates = {}; | |
Set<String> flutterDates = {}; | |
RegExp dateRegex = new RegExp(r"\d{4}-\d{2}-\d{2}"); | |
for (String line in lines) { | |
if (line.trim().isEmpty) { | |
continue; | |
} | |
final String date =dateRegex.stringMatch(line).toString(); | |
dates.add(date); | |
if (line.contains('flutter run')) { | |
flutterDates.add(date); | |
} | |
} | |
printAnalysis('flutter run', flutterDates); | |
printAnalysis('command line', dates); | |
} | |
void main() { | |
new File('history.out').readAsLines().then(processLines); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment