Skip to content

Commit

Permalink
Merge pull request #266 from COS301-SE-2024/dev/feat/offlineBirds
Browse files Browse the repository at this point in the history
🔀Merge branches Dev/feat/offline birds
  • Loading branch information
ChuufMaster authored Sep 22, 2024
2 parents 9fa1f58 + 74274bb commit 40c7f94
Show file tree
Hide file tree
Showing 14 changed files with 13,836 additions and 1,259 deletions.
14,523 changes: 13,399 additions & 1,124 deletions beakpeek/assets/BirdList/allbirds.json

Large diffs are not rendered by default.

92 changes: 0 additions & 92 deletions beakpeek/lib/Controller/DB/achievements_provider.dart

This file was deleted.

108 changes: 108 additions & 0 deletions beakpeek/lib/Controller/DB/birds_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// // ignore_for_file: avoid_print

// import 'package:beakpeek/Model/BirdInfo/bird.dart';
// import 'package:beakpeek/Model/BirdInfo/pentad.dart';
// import 'package:beakpeek/Model/BirdInfo/province.dart';
// import 'package:sqflite/sqflite.dart';

// class BirdsProvider {

// static Database? lifeList;


// Future<List<Bird>> fetchBirds() async {
// final db = await instance.database;

// final List<Map<String, Object?>> birdMap = await db.query(
// 'birds',
// orderBy: 'commonGroup DESC, commonSpecies DESC',
// );
// return birdMap.map(
// (map) {
// return Bird(
// id: map['id'] as int,
// commonGroup:
// map['commonGroup'] != null ? map['commonGroup'] as String : '',
// commonSpecies: map['commonSpecies'] != null
// ? map['commonSpecies'] as String
// : '',
// fullProtocolRR: 0.0,
// fullProtocolNumber: 0,
// latestFP: map['latestFP'] != null ? map['latestFP'] as String : '',
// reportingRate: map['reportingRate'] != null
// ? map['reportingRate'] as double
// : 0.0,
// genus: map['genus'] as String,
// species: map['species'] as String,
// pentad: Pentad(
// pentadAllocation: map['pentad'].toString(),
// pentadLongitude: 0.0,
// pentadLatitude: 0.0,
// province: Province(
// id: 0,
// name: ' ',
// ),
// totalCards: 0,
// ),
// jan: 0.0,
// feb: 0.0,
// mar: 0.0,
// apr: 0.0,
// may: 0.0,
// jun: 0.0,
// jul: 0.0,
// aug: 0.0,
// sep: 0.0,
// oct: 0.0,
// nov: 0.0,
// dec: 0.0,
// totalRecords: 0,
// );
// },
// ).toList();
// }

// Future close() async {
// final db = await instance.database;
// db.close();
// }

// Future<bool> isDuplicate(Bird bird) async {
// final db = await instance.database;
// final maps = await db.query(
// 'birds',
// columns: ['commonGroup', 'commonSpecies', 'genus', 'species'],
// where:
// 'commonGroup = ? AND commonSpecies = ? AND genus = ? AND species =?',
// whereArgs: [
// bird.commonGroup,
// bird.commonSpecies,
// bird.genus,
// bird.species
// ],
// );

// if (maps.isNotEmpty) {
// return true;
// } else {
// return false;
// }
// }

// Future<void> delete(Bird bird) async {
// final db = await instance.database;
// await db.delete(
// 'birds',
// where:
// '''commonGroup = ? AND commonSpecies = ? AND genus = ? AND species =?''',
// whereArgs: [
// bird.commonGroup,
// bird.commonSpecies,
// bird.genus,
// bird.species
// ],
// );
// }


// }
22 changes: 20 additions & 2 deletions beakpeek/lib/Controller/DB/database_calls.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
// ignore_for_file: avoid_print
import 'dart:convert';
import 'package:beakpeek/Controller/DB/life_list_provider.dart';
import 'package:beakpeek/Model/BirdInfo/bird.dart';
import 'package:beakpeek/Model/BirdInfo/bird_search_functions.dart';
import 'package:http/http.dart' as http;

const List<String> provinces = [
'easterncape',
'freestate',
'gauteng',
'kwazulunatal',
'limpopo',
'mpumalanga',
'northerncape',
'northwest',
'westerncape'
'westerncape',
'freestate',
];

Future<List<Bird>> fetchAllBirds(String prov, http.Client client) async {
Expand Down Expand Up @@ -80,3 +81,20 @@ Future<List> getProvincesBirdIsIn(
throw Exception('Failed to load number of birds: $error, ');
}
}

Future<List<bool>> getProvincesForBird(int id) async {
late final LifeListProvider lifeList = LifeListProvider.instance;
late final List<bool> isIn = [];
await lifeList.getBirdProvinces(id).then((prov) {
isIn.add((prov.easterncape));
isIn.add((prov.gauteng));
isIn.add((prov.kwazulunatal));
isIn.add((prov.limpopo));
isIn.add((prov.mpumalanga));
isIn.add((prov.northerncape));
isIn.add((prov.northwest));
isIn.add((prov.westerncape));
isIn.add((prov.freestate));
});
return isIn;
}
Loading

0 comments on commit 40c7f94

Please sign in to comment.