Skip to content

Commit

Permalink
lint, small fix for spare criticality calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmajh committed Nov 13, 2023
1 parent c4be0b3 commit 7398898
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 84 deletions.
4 changes: 2 additions & 2 deletions lib/admin/pm_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ class _PmCheckPageState extends State<PmCheckPage> {
}

Future<void> pickTemplates(BuildContext context) async {
final template = context.read<TemplateNotifier>();
final maximo = context.read<MaximoServerNotifier>();
Stopwatch stopwatch = Stopwatch()..start();
FilePickerResult? result = await FilePicker.platform
.pickFiles(allowMultiple: true, withData: true);
Expand All @@ -309,8 +311,6 @@ class _PmCheckPageState extends State<PmCheckPage> {
setState(() {
debugPrint('Processing files...');
});
final template = context.read<TemplateNotifier>();
final maximo = context.read<MaximoServerNotifier>();
processAllTemplates(template, files, maximo.maximoServerSelected);
}
}
Expand Down
21 changes: 0 additions & 21 deletions lib/admin/pm_meter_update_functions.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import 'package:iko_reliability_flutter/admin/generate_uploads.dart';

import '../bin/db_drift.dart';
import 'upload_maximo.dart';

class AssetMeterMaximo {
Expand Down Expand Up @@ -72,21 +69,3 @@ List<String> assetMeterPairs(
}
return result;
}

List<JobPlanMeterCheckMaximo> jobTaskUpdates(
List<JobPlanMeterCheckMaximo> jobplans, Meter meterDetails) {
List<JobPlanMeterCheckMaximo> result = [];
final details = jobTaskFormat(meterDetails.description);
for (final jobplan in jobplans) {
if (details != jobplan.details) {
result.add(jobplan);
continue;
}
// TODO more comparisons
// description
// metercode
// ignore CBM for now
}

return result;
}
18 changes: 9 additions & 9 deletions lib/bin/end_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class _EndDrawerState extends State<EndDrawer> {
passwordController.text,
maximo.maximoServerSelected);
} finally {
ScaffoldMessenger.of(context)
ScaffoldMessenger.of(navigatorKey.currentContext!)
.hideCurrentSnackBar(); //hide snackbar once process is complete
processNotifier.setProcessState(
ProcessStates.loginState, false);
Expand Down Expand Up @@ -226,7 +226,8 @@ class _EndDrawerState extends State<EndDrawer> {
));
List<String> messages = await maximoAssetCaller(
siteid, maximo.maximoServerSelected, context);
processNotifier.popProcessingDialog(context);
processNotifier.popProcessingDialog(
navigatorKey.currentContext!);
if (messages.isNotEmpty) {
showDataAlert(messages, 'Site Assets Loaded');
}
Expand Down Expand Up @@ -341,7 +342,7 @@ class _EndDrawerState extends State<EndDrawer> {
context.read<SelectedSiteNotifier>().selectedSite,
)),
));
Navigator.of(context).pop();
Navigator.of(navigatorKey.currentContext!).pop();
}),
),
ListTile(
Expand All @@ -354,7 +355,7 @@ class _EndDrawerState extends State<EndDrawer> {
database!,
)),
));
Navigator.of(context).pop();
Navigator.of(navigatorKey.currentContext!).pop();
}),
),
]),
Expand Down Expand Up @@ -390,6 +391,8 @@ class _EndDrawerState extends State<EndDrawer> {
trailing: ElevatedButton(
child: const Text('Export'),
onPressed: () async {
PlutoGridStateManager? stateManager =
context.read<AssetCriticalityNotifier>().stateManager;
if (!context
.read<AssetCriticalityNotifier>()
.priorityRangesUpToDate) {
Expand All @@ -399,9 +402,6 @@ class _EndDrawerState extends State<EndDrawer> {
return;
}
}
PlutoGridStateManager? stateManager =
context.read<AssetCriticalityNotifier>().stateManager;

//export as csv
if (stateManager != null) {
exportAssetCriticalityAsCSV(
Expand All @@ -422,7 +422,7 @@ class _EndDrawerState extends State<EndDrawer> {
context.read<SelectedSiteNotifier>().selectedSite,
)),
));
Navigator.of(context).pop();
Navigator.of(navigatorKey.currentContext!).pop();
}),
),
ListTile(
Expand All @@ -435,7 +435,7 @@ class _EndDrawerState extends State<EndDrawer> {
database!,
)),
));
Navigator.of(context).pop();
Navigator.of(navigatorKey.currentContext!).pop();
}),
),
],
Expand Down
23 changes: 13 additions & 10 deletions lib/creation/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ class _AssetCreationGridState extends State<AssetCreationGrid> {
context.read<SelectedSiteNotifier>().selectedSite);
stateManager
.removeRows([rendererContext.row], notify: true);
toast(context, 'Deleted Asset $assetNum');
toast(navigatorKey.currentContext!,
'Deleted Asset $assetNum');
} catch (err) {
toast(context, '$err');
toast(navigatorKey.currentContext!, '$err');
}
},
iconSize: 18,
Expand Down Expand Up @@ -257,12 +258,12 @@ class _AssetCreationGridState extends State<AssetCreationGrid> {
}

Future<void> _loadGrid(String site) async {
final assetCreationNotifier =
Provider.of<AssetCreationNotifier>(context, listen: false);
await context
.read<AssetCreationNotifier>()
.setSite(context.read<SelectedSiteNotifier>().selectedSite);
print('load grid');
final assetCreationNotifier =
Provider.of<AssetCreationNotifier>(context, listen: false);
debugPrint('load grid');

var fetchedRows = _getChildRows('Top', assetCreationNotifier.parentAssets);
var value =
Expand Down Expand Up @@ -604,12 +605,13 @@ class _AssetCreationDialogState extends State<AssetCreationDialog> {
context
.read<SelectedSiteNotifier>()
.setSite(context.read<SelectedSiteNotifier>().selectedSite);
toast(context, 'Created Asset $assetNum, id: $id');
toast(navigatorKey.currentContext!,
'Created Asset $assetNum, id: $id');
} catch (err) {
toast(context, '$err');
toast(navigatorKey.currentContext!, '$err');
}

Navigator.pop(context, 'OK');
Navigator.pop(navigatorKey.currentContext!, 'OK');
},
child: const Text('OK'),
),
Expand Down Expand Up @@ -665,9 +667,10 @@ class _AssetUploadGridState extends State<AssetUploadGrid> {
context.read<SelectedSiteNotifier>().selectedSite);
stateManager
.removeRows([rendererContext.row], notify: true);
toast(context, 'Deleted Asset $assetNum');
toast(navigatorKey.currentContext!,
'Deleted Asset $assetNum');
} catch (err) {
toast(context, '$err');
toast(navigatorKey.currentContext!, '$err');
}
},
iconSize: 18,
Expand Down
2 changes: 1 addition & 1 deletion lib/creation/asset_creation_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class AssetCreationNotifier extends ChangeNotifier {
pendingAssets.remove(assetNum);

var parent = siteAssets[assetNum]!.asset.parent;
parentAssets[parent]!.remove(siteAssets[assetNum]!);
parentAssets[parent]!.remove(siteAssets[assetNum]!.asset);
if (parentAssets[parent]!.isEmpty) {
parentAssets.remove(parent);
}
Expand Down
48 changes: 29 additions & 19 deletions lib/criticality/asset_criticality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,13 @@ class _AssetCriticalityPageState extends State<AssetCriticalityPage> {
downtime: rendererContext.row.cells['downtime']!.value,
system: rendererContext.row.cells['system']!.value,
);
context.read<AssetOverrideNotifier>().updateAssetOverride(
assets: [rendererContext.row.cells['assetnum']!.value],
status: AssetOverride.breakdowns,
);

if (context.mounted) {
context.read<AssetOverrideNotifier>().updateAssetOverride(
assets: [rendererContext.row.cells['assetnum']!.value],
status: AssetOverride.breakdowns,
);
}
setState(() {
stateManager.changeCellValue(rendererContext.cell, value);
});
Expand Down Expand Up @@ -325,10 +328,12 @@ class _AssetCriticalityPageState extends State<AssetCriticalityPage> {
frequency: rendererContext.row.cells['frequency']!.value,
system: rendererContext.row.cells['system']!.value,
);
context.read<AssetOverrideNotifier>().updateAssetOverride(
assets: [rendererContext.row.cells['assetnum']!.value],
status: AssetOverride.breakdowns,
);
if (context.mounted) {
context.read<AssetOverrideNotifier>().updateAssetOverride(
assets: [rendererContext.row.cells['assetnum']!.value],
status: AssetOverride.breakdowns,
);
}
setState(() {
stateManager.changeCellValue(rendererContext.cell, value);
});
Expand Down Expand Up @@ -374,10 +379,12 @@ class _AssetCriticalityPageState extends State<AssetCriticalityPage> {
system: rendererContext.row.cells['system']!.value,
frequency: rendererContext.row.cells['frequency']!.value,
);
context.read<AssetOverrideNotifier>().updateAssetOverride(
assets: [rendererContext.row.cells['assetnum']!.value],
status: AssetOverride.priority,
);
if (context.mounted) {
context.read<AssetOverrideNotifier>().updateAssetOverride(
assets: [rendererContext.row.cells['assetnum']!.value],
status: AssetOverride.priority,
);
}
setState(() {
stateManager.changeCellValue(rendererContext.cell, value);
});
Expand Down Expand Up @@ -543,6 +550,8 @@ class _AssetCriticalityPageState extends State<AssetCriticalityPage> {
assets: [assetnum],
status: AssetStatus.refreshingWorkOrders,
);
AssetCriticalitySettingsNotifier assetCriticalitySettings =
context.read<AssetCriticalitySettingsNotifier>();
// get all WOs from Maximo
try {
await database!.getWorkOrderMaximo(
Expand All @@ -551,22 +560,23 @@ class _AssetCriticalityPageState extends State<AssetCriticalityPage> {
);
} catch (e) {
previousStatus = AssetStatus.refreshError;
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
ScaffoldMessenger.of(navigatorKey.currentContext!).showSnackBar(SnackBar(
content: Text(
'Error retriving Work Orders from Maximo for: $assetnum \n ${e.toString()}'),
));
return;
}
// bring back previous status Icon
context.read<AssetStatusNotifier>().updateAssetStatus(
assets: [assetnum],
status: previousStatus,
);
if (context.mounted) {
context.read<AssetStatusNotifier>().updateAssetStatus(
assets: [assetnum],
status: previousStatus,
);
}
var wos = await database!.getAssetWorkorders(assetnum);
double downtime = 0;
double dtEvents = 0;
AssetCriticalitySettingsNotifier assetCriticalitySettings =
context.read<AssetCriticalitySettingsNotifier>();

for (var wo in wos) {
if (!isWorkOrderInRange(wo)) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/criticality/criticality_settings_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ List<double> calculateSingleCutoff({
int i = 1;
double currentPercent = 0;
double previousPercent = 0;
int sumRPNs = 0;
// calculation for very low
while (i <= sortedUniqueRPNs.length) {
int sumRPNs = 0;
sortedUniqueRPNs.sublist(0, i).forEach((element) {
sumRPNs = sumRPNs + frequencyOfRPNs[element]!;
});
Expand Down
4 changes: 3 additions & 1 deletion lib/criticality/file_export.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:pluto_grid/pluto_grid.dart';
import '../admin/generate_uploads.dart';
import 'package:csv/csv.dart';

import '../main.dart';

///Saves string contents into a file selected by the user. Shows a file picker dialog.
///Returns [true] if file is saved, [false] if canceled, and an exception object if there was an error.
///Saves file in utf-8 with BOM encoding
Expand Down Expand Up @@ -45,7 +47,7 @@ Future<dynamic> saveFileFromString(String contents,
debugPrint('File type not supported');
if (context != null) {
await showDialog(
context: context,
context: navigatorKey.currentContext!,
builder: (context) => AlertDialog(
title: const Text('Unsupported File Type'),
content: Text(
Expand Down
27 changes: 15 additions & 12 deletions lib/criticality/spare_criticality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class _SpareCriticalityPageState extends State<SpareCriticalityPage> {
]))
.toList();
showDialog(
context: context,
context: navigatorKey.currentContext!,
builder: (BuildContext context) {
return Dialog(
child: DataTable(columns: const [
Expand Down Expand Up @@ -538,14 +538,16 @@ class _SpareCriticalityPageState extends State<SpareCriticalityPage> {
spareid: event.row.cells['id']!.value,
);
event.row.cells['rpn']!.value = newRpn;
final newPriority = context
.read<SpareCriticalityNotifier>()
.rpnFindDistribution(newRpn);
if (event.row.cells['override']!.value !=
AssetOverride.priority) {
event.row.cells['newPriority']!.value = newPriority;
event.row.cells['override']!.value =
AssetOverride.breakdowns;
if (context.mounted) {
final newPriority = context
.read<SpareCriticalityNotifier>()
.rpnFindDistribution(newRpn);
if (event.row.cells['override']!.value !=
AssetOverride.priority) {
event.row.cells['newPriority']!.value = newPriority;
event.row.cells['override']!.value =
AssetOverride.breakdowns;
}
}
}
},
Expand Down Expand Up @@ -756,9 +758,9 @@ class _SparePartsLoadingIndicatorState
return;
}
}
Navigator.pop(context);
context.router.pushNamed("/criticality/spare");
Navigator.pop(context); // close the drawer
Navigator.pop(navigatorKey.currentContext!);
navigatorKey.currentContext!.router.pushNamed("/criticality/spare");
Navigator.pop(navigatorKey.currentContext!); // close the drawer
}
}

Expand Down Expand Up @@ -920,6 +922,7 @@ Future<String> calculateRPNDistributionSpares(BuildContext context) async {
return 'Duplicate values in RPN cutoffs\nIncrease percentage of duplicate value, Or ensure RPN values are more spread out';
}
spareCritifcalityNotifier.updateGrid = true;
debugPrint(spareCritifcalityNotifier.updateGrid.toString());
} catch (e) {
debugPrint(e.toString());
return e.toString();
Expand Down
5 changes: 3 additions & 2 deletions lib/criticality/system_criticality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,11 @@ class _NewSystemFormState extends State<NewSystemForm> {
newRow.cells['line']!.value = row.line;
newRow.cells['description']!.value = row.description;
stateManager.appendRows([newRow]);
ScaffoldMessenger.of(context).showSnackBar(
ScaffoldMessenger.of(navigatorKey.currentContext!)
.showSnackBar(
const SnackBar(content: Text('Adding New System')),
);
Navigator.of(context).pop();
Navigator.of(navigatorKey.currentContext!).pop();
}
},
child: const Text('Submit'),
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MyApp extends StatelessWidget {

Future<void> loadAppSettings(SelectedSiteNotifier selectedSiteNotifier,
ThemeManager themeManager, SettingsNotifier settingsNotifier) async {
print('running load app');
debugPrint('running load app');
final settings = await database!.getSettings();
final selectedSite = settings
.firstWhere(
Expand Down
5 changes: 0 additions & 5 deletions lib/settings/settings_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ class SettingsNotifier extends ChangeNotifier {
return currentSettings[settingKey];
}

///Gets an int list of the rpn percent distributions from very low to very high
List<int> getRpnPercentDists() {
return List.from(criticalityStrings.map((e) => currentSettings[e]));
}

void addLoadedSites(List<String> sites, {bool notify = false}) {
Set<String> newSet =
(currentSettings[ApplicationSetting.loadedSites] as Set<String>)
Expand Down

0 comments on commit 7398898

Please sign in to comment.