From 67e12bc590b6dfa029013d316a63778484e37e0d Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Wed, 10 Jul 2019 17:28:02 -0400 Subject: [PATCH] ver app updates --- .../packages/lbry/lib/src/load_generator.dart | 3 +- dart/packages/ver/lib/main.dart | 119 +++------------- dart/packages/ver/lib/time_series_chart.dart | 132 ++++++++++++++++++ dart/packages/ver/lib/utils.dart | 13 ++ .../ver/linux/flutter_embedder_example.cc | 2 +- dart/packages/ver/pubspec.lock | 35 +++++ dart/packages/ver/pubspec.yaml | 45 +----- 7 files changed, 208 insertions(+), 141 deletions(-) create mode 100644 dart/packages/ver/lib/time_series_chart.dart create mode 100644 dart/packages/ver/lib/utils.dart diff --git a/dart/packages/lbry/lib/src/load_generator.dart b/dart/packages/lbry/lib/src/load_generator.dart index 79ead0f6c..380970268 100644 --- a/dart/packages/lbry/lib/src/load_generator.dart +++ b/dart/packages/lbry/lib/src/load_generator.dart @@ -92,6 +92,7 @@ class LoadGenerator { } } stat.backlog = backlog.length; + stat.load = load; if (cb(this, stat)) { previous = spawn_requests(); } else { @@ -107,7 +108,7 @@ class LoadGenerator { List spawn_requests() { var requests = []; for (var _ in Iterable.generate(load)) { - requests.add(LoadRequest.resolve().start()); + requests.add(LoadRequest.search().start()); } return requests; } diff --git a/dart/packages/ver/lib/main.dart b/dart/packages/ver/lib/main.dart index 6842aff71..4275f61b8 100644 --- a/dart/packages/ver/lib/main.dart +++ b/dart/packages/ver/lib/main.dart @@ -1,126 +1,49 @@ -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride; +import 'package:ver/utils.dart'; +import 'package:ver/time_series_chart.dart'; -TargetPlatform getTargetPlatformForDesktop() { - if (Platform.isMacOS || Platform.isIOS) { - return TargetPlatform.iOS; - } else if (Platform.isAndroid) { - return TargetPlatform.android; - } - return TargetPlatform.fuchsia; -} -void main() { - // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override - debugDefaultTargetPlatformOverride = getTargetPlatformForDesktop(); - runApp(new MyApp()); -} - -class MyApp extends StatelessWidget { - // This widget is the root of your application. +class VerApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: 'Flutter Demo', + title: 'Ver', theme: ThemeData( - // This is the theme of your application. - // - // Try running your application with "flutter run". You'll see the - // application has a blue toolbar. Then, without quitting the app, try - // changing the primarySwatch below to Colors.green and then invoke - // "hot reload" (press "r" in the console where you ran "flutter run", - // or simply save your changes to "hot reload" in a Flutter IDE). - // Notice that the counter didn't reset back to zero; the application - // is not restarted. - primarySwatch: Colors.blue, + brightness: Brightness.light, + primarySwatch: Colors.lightBlue, + fontFamily: 'Roboto', ), - home: MyHomePage(title: 'Flutter Demo Home Page'), + home: VerHomePage(title: 'Wallet Server'), ); } } -class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". +class VerHomePage extends StatefulWidget { + VerHomePage({Key key, this.title}) : super(key: key); final String title; - @override - _MyHomePageState createState() => _MyHomePageState(); + _VerHomePageState createState() => _VerHomePageState(); } -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. - _counter++; - }); - } - +class _VerHomePageState extends State { @override Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. return Scaffold( appBar: AppBar( - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. title: Text(widget.title), ), - body: Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. - child: Column( - // Column is also a layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Invoke "debug painting" (press "p" in the console, choose the - // "Toggle Debug Paint" action from the Flutter Inspector in Android - // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) - // to see the wireframe for each widget. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.display1, - ), - ], - ), + body: new Padding( + padding: const EdgeInsets.all(8.0), + child: SimpleTimeSeriesChart() ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. ); } } + + +void main() { + debugDefaultTargetPlatformOverride = getTargetPlatformForDesktop(); + runApp(new VerApp()); +} diff --git a/dart/packages/ver/lib/time_series_chart.dart b/dart/packages/ver/lib/time_series_chart.dart new file mode 100644 index 000000000..ebbdaafb6 --- /dev/null +++ b/dart/packages/ver/lib/time_series_chart.dart @@ -0,0 +1,132 @@ +import 'dart:math'; +import 'package:flutter/material.dart'; +import 'package:charts_flutter/flutter.dart' as charts; +import 'package:charts_flutter/src/base_chart_state.dart' as state; +import 'package:charts_common/common.dart' as common; +import 'package:lbry/lbry.dart'; + + +class SimpleTimeSeriesChart extends StatefulWidget { + SimpleTimeSeriesChart({Key key}) : super(key: key); + @override + _SimpleTimeSeriesChartState createState() => _SimpleTimeSeriesChartState(); +} + + +class _SimpleTimeSeriesChartState extends State { + final List loadData = []; + final List> loadSeries = []; + final List> timeSeries = []; + final Random rand = Random(); + LoadGenerator loadGenerator; + + @override + void initState() { + super.initState(); + loadSeries.add( + charts.Series( + id: 'Load', + colorFn: (_, __) => charts.MaterialPalette.black.darker, + domainFn: (LoadDataPoint load, _) => load.time, + measureFn: (LoadDataPoint load, _) => load.load, + data: loadData, + ) + ); + loadSeries.add( + charts.Series( + id: 'Success', + colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, + domainFn: (LoadDataPoint load, _) => load.time, + measureFn: (LoadDataPoint load, _) => load.success, + data: loadData, + ) + ); + loadSeries.add( + charts.Series( + id: 'Backlog', + colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, + domainFn: (LoadDataPoint load, _) => load.time, + measureFn: (LoadDataPoint load, _) => load.backlog, + data: loadData, + ) + ); + loadSeries.add( + charts.Series( + id: 'Catch-up', + colorFn: (_, __) => charts.MaterialPalette.yellow.shadeDefault, + domainFn: (LoadDataPoint load, _) => load.time, + measureFn: (LoadDataPoint load, _) => load.catchup, + data: loadData, + ) + ); + timeSeries.add( + charts.Series( + id: 'Avg. Success Time', + colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, + domainFn: (LoadDataPoint load, _) => load.time, + measureFn: (LoadDataPoint load, _) => load.avg_success, + data: loadData, + ) + ); + timeSeries.add( + charts.Series( + id: 'Avg. Catch-up Time', + colorFn: (_, __) => charts.MaterialPalette.yellow.shadeDefault, + domainFn: (LoadDataPoint load, _) => load.time, + measureFn: (LoadDataPoint load, _) => load.avg_catchup, + data: loadData, + ) + ); + var increase = 2; + loadData.add(LoadDataPoint()); + loadGenerator = LoadGenerator((t, stats) { + setState(() { + //if (loadData.length > 60) loadData.removeAt(0); + loadData.add(stats); + }); + increase = max(1, min(30, (increase*1.1).ceil())-stats.backlog); + t.load = increase;//rand.nextInt(10)+5; + return true; + })..start(); + } + + @override + void dispose() { + loadGenerator.stop(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Column(children: [ + SizedBox(height: 250.0, child: BetterTimeSeriesChart(loadSeries)), + SizedBox(height: 250.0, child: BetterTimeSeriesChart(timeSeries)), + ]); + } + +} + + +class BetterTimeSeriesChart extends charts.TimeSeriesChart { + + final int itemCount; + final Object lastItem; + + BetterTimeSeriesChart( + List> seriesList): + itemCount = seriesList[0].data.length, + lastItem = seriesList[0].data.last, + super(seriesList, behaviors: [charts.SeriesLegend()]); + + @override + void updateCommonChart(common.BaseChart baseChart, charts.BaseChart oldWidget, + state.BaseChartState chartState) { + super.updateCommonChart(baseChart, oldWidget, chartState); + final prev = oldWidget as BetterTimeSeriesChart; + if (itemCount != prev?.itemCount || lastItem != prev?.lastItem) { + chartState.markChartDirty(); + } + } + +} + diff --git a/dart/packages/ver/lib/utils.dart b/dart/packages/ver/lib/utils.dart new file mode 100644 index 000000000..a202edaee --- /dev/null +++ b/dart/packages/ver/lib/utils.dart @@ -0,0 +1,13 @@ +import 'dart:io'; +import 'package:flutter/foundation.dart'; + +TargetPlatform getTargetPlatformForDesktop() { + // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override + if (Platform.isMacOS || Platform.isIOS) { + return TargetPlatform.iOS; + } else if (Platform.isAndroid) { + return TargetPlatform.android; + } + return TargetPlatform.fuchsia; +} + diff --git a/dart/packages/ver/linux/flutter_embedder_example.cc b/dart/packages/ver/linux/flutter_embedder_example.cc index d87734f4c..e924a52ce 100644 --- a/dart/packages/ver/linux/flutter_embedder_example.cc +++ b/dart/packages/ver/linux/flutter_embedder_example.cc @@ -60,7 +60,7 @@ int main(int argc, char **argv) { flutter::FlutterWindowController flutter_controller(icu_data_path); // Start the engine. - if (!flutter_controller.CreateWindow(800, 600, "Flutter Desktop Example", + if (!flutter_controller.CreateWindow(800, 600, "ver - lbry workbench", assets_path, arguments)) { return EXIT_FAILURE; } diff --git a/dart/packages/ver/pubspec.lock b/dart/packages/ver/pubspec.lock index 221d92978..602b29ecc 100644 --- a/dart/packages/ver/pubspec.lock +++ b/dart/packages/ver/pubspec.lock @@ -50,6 +50,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.2" + fixnum: + dependency: transitive + description: + name: fixnum + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.9" flutter: dependency: "direct main" description: flutter @@ -60,6 +67,20 @@ packages: description: flutter source: sdk version: "0.0.0" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.0+2" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.3" intl: dependency: transitive description: @@ -67,6 +88,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.15.8" + lbry: + dependency: "direct main" + description: + path: "../lbry" + relative: true + source: path + version: "0.0.1" logging: dependency: transitive description: @@ -102,6 +130,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0+1" + protobuf: + dependency: transitive + description: + name: protobuf + url: "https://pub.dartlang.org" + source: hosted + version: "0.13.14" quiver: dependency: transitive description: diff --git a/dart/packages/ver/pubspec.yaml b/dart/packages/ver/pubspec.yaml index 4431ec9f0..717c8e5b4 100644 --- a/dart/packages/ver/pubspec.yaml +++ b/dart/packages/ver/pubspec.yaml @@ -1,6 +1,8 @@ name: ver description: An app for LBRY. version: 0.0.1+1 +homepage: https://lbry.com +author: LBRY Inc. environment: sdk: ">=2.1.0 <3.0.0" @@ -10,54 +12,15 @@ dependencies: sdk: flutter cupertino_icons: ^0.1.2 charts_flutter: ^0.6.0 + lbry: + path: ../lbry dev_dependencies: flutter_test: sdk: flutter - -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter. flutter: - - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. uses-material-design: true - - # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware. - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/assets-and-images/#from-packages - - # To add custom fonts to your application, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/custom-fonts/#from-packages - # See https://github.com/flutter/flutter/wiki/Desktop-shells#fonts fonts: - family: Roboto