Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: aed event properties #19

Merged
merged 9 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions lib/bloc/edit/edit_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,15 @@ class EditCubit extends Cubit<EditState> {
await pointsRepository.insertDefibrillator(s.aed);
analytics.event(name: saveInsertEvent);
if (!Platform.environment.containsKey('FLUTTER_TEST')) {
mixpanel.track(saveInsertEvent, properties: {
'aed_id': s.aed.id,
'aed_node_url': osmNodePrefix + s.aed.id.toString()
});
mixpanel.track(saveInsertEvent,
properties: s.aed.getEventProperties());
}
} else {
await pointsRepository.updateDefibrillator(s.aed);
analytics.event(name: saveUpdateEvent);
if (!Platform.environment.containsKey('FLUTTER_TEST')) {
mixpanel.track(saveUpdateEvent, properties: {
'aed_id': s.aed.id,
'aed_node_url': osmNodePrefix + s.aed.id.toString()
});
mixpanel.track(saveUpdateEvent,
properties: s.aed.getEventProperties());
}
}
emit(EditReady(enabled: false, cursor: state.cursor));
Expand Down
17 changes: 10 additions & 7 deletions lib/bloc/points/points_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PointsCubit extends Cubit<PointsState> {
.logSelectContent(contentType: 'aed', itemId: aed.id.toString());
HapticFeedback.mediumImpact();
analytics.event(name: selectEvent);
mixpanel.track(selectEvent, properties: {'aed': aed.id});
mixpanel.track(selectEvent, properties: aed.getEventProperties());
if (state is PointsLoadSuccess) {
emit((state as PointsLoadSuccess)
.copyWith(selected: aed, hash: generateRandomString(32)));
Expand All @@ -69,14 +69,17 @@ class PointsCubit extends Cubit<PointsState> {
update(AED aed) {
if (state is PointsLoadSuccess) {
if (aed.id == 0) {
var newDefibrillators = List<AED>.from((state as PointsLoadSuccess).aeds)
..insert(0, aed);
var newDefibrillators =
List<AED>.from((state as PointsLoadSuccess).aeds)..insert(0, aed);
emit((state as PointsLoadSuccess).copyWith(
aeds: newDefibrillators, markers: _getMarkers(newDefibrillators), selected: aed));
aeds: newDefibrillators,
markers: _getMarkers(newDefibrillators),
selected: aed));
} else {
var updatedDefibrillators = List<AED>.from((state as PointsLoadSuccess).aeds)
..removeWhere((x) => x.id == aed.id)
..insert(0, aed);
var updatedDefibrillators =
List<AED>.from((state as PointsLoadSuccess).aeds)
..removeWhere((x) => x.id == aed.id)
..insert(0, aed);
emit((state as PointsLoadSuccess).copyWith(
selected: aed,
aeds: updatedDefibrillators,
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/routing/routing_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RoutingCubit extends Cubit<RoutingState> {
}
if (!Platform.environment.containsKey('FLUTTER_TEST')) {
FirebaseAnalytics.instance.logSearch(searchTerm: aed.id.toString());
mixpanel.track(navigateEvent, properties: {'aed': aed.id});
mixpanel.track(navigateEvent, properties: aed.getEventProperties());
}
}

Expand Down
16 changes: 16 additions & 0 deletions lib/models/aed.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:aed_map/constants.dart';
import 'package:flutter/material.dart';
import 'package:latlong2/latlong.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -156,6 +157,21 @@ class AED {
image: image ?? this.image,
);
}

Map<String, dynamic> getEventProperties() {
return {
'aed_id': id,
'aed_node_url': osmNodePrefix + id.toString(),
'aed_latityde': location.latitude,
'aed_longitude': location.longitude,
'aed_indoor': indoor,
'aed_operator': operator,
'aed_phone': phone,
'aed_distance': distance,
'aed_opening_hours': openingHours,
'aed_access': access
};
}
}

String translateAccessComment(
Expand Down
11 changes: 10 additions & 1 deletion lib/models/user.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
class User {
final int id;
final String name;
final String? avatar;

User({required this.id, required this.name});
User({required this.id, required this.name, this.avatar});

User copyWith({int? id, String? name, String? avatar}) {
return User(
id: id ?? this.id,
name: name ?? this.name,
avatar: avatar ?? this.avatar,
);
}
}
28 changes: 26 additions & 2 deletions lib/repositories/points_repository.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:io';

import 'package:aed_map/constants.dart';
import 'package:aed_map/main.dart';
Expand Down Expand Up @@ -48,6 +49,14 @@ class PointsRepository {
}

Future<List<AED>> loadAEDs(LatLng currentLocation) async {
if (!Platform.environment.containsKey('FLUTTER_TEST')) {
await mixpanel.registerSuperProperties({
"\$latitude": currentLocation.latitude,
"\$longitude": currentLocation.longitude
});
mixpanel.getPeople().set('\$latitude', currentLocation.latitude);
mixpanel.getPeople().set('\$longitude', currentLocation.longitude);
}
List<AED> aeds = [];
SharedPreferences prefs = await SharedPreferences.getInstance();
if (!prefs.containsKey(aedListKey)) await loadLocalAEDs();
Expand Down Expand Up @@ -108,6 +117,7 @@ class PointsRepository {
print('Got OAuth2 token: $token');
}
mixpanel.track(authenticatedEvent);
await getUser();
return token != null;
} on Exception catch (_) {
return false;
Expand All @@ -122,14 +132,28 @@ class PointsRepository {
var response = await http.get(
Uri.parse('https://api.openstreetmap.org/api/0.6/user/details.json'),
headers: {'Authorization': 'Bearer $token'});
var user = json.decode(response.body)['user'];
return User(id: user['id'], name: user['display_name']);
var payload = json.decode(response.body)['user'];
var user = User(id: payload['id'], name: payload['display_name']);
if (payload.containsKey('img')) {
user = user.copyWith(avatar: payload['img']['href']);
}
if (!Platform.environment.containsKey('FLUTTER_TEST')) {
mixpanel.identify(user.id.toString());
mixpanel.getPeople().set('\$user_id', user.id);
mixpanel.getPeople().set('\$name', user.name);
mixpanel.getPeople().set('\$avatar', user.avatar);
await mixpanel.flush();
}
return user;
} catch (err) {
return User(id: 0, name: 'Unknown');
}
}

Future<void> logout() async {
if (!Platform.environment.containsKey('FLUTTER_TEST')) {
await mixpanel.reset();
}
token = null;
}

Expand Down
25 changes: 13 additions & 12 deletions lib/screens/edit/edit_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,19 @@ class EditForm extends StatelessWidget {
: Colors.black))),
],
),
SettingsSection(
title: Text('OpenStreetMap'),
tiles: [
SettingsTile.navigation(
leading: const Icon(CupertinoIcons.cube_box),
title: Text(appLocalizations.viewOpenStreetMapNode),
onPressed: (context) {
launchUrl(Uri.parse('$osmNodePrefix${state.aed.id}'));
},
),
],
),
if (state.aed.id > 0)
SettingsSection(
title: Text('OpenStreetMap'),
tiles: [
SettingsTile.navigation(
leading: const Icon(CupertinoIcons.cube_box),
title: Text(appLocalizations.viewOpenStreetMapNode),
onPressed: (context) {
launchUrl(Uri.parse('$osmNodePrefix${state.aed.id}'));
},
),
],
),
CustomSettingsSection(
child: Padding(
padding: const EdgeInsets.only(top: 8.0, left: 16, right: 16),
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"watch-css": "tailwindcss build -i src/tailwind/tailwind.css -c src/tailwind/tailwind.config.js -o public/css/tailwind/tailwind.min.css --minify --watch"
},
"dependencies": {
"input": "^1.0.1",
"intl": "^1.2.5",
"openai": "^4.80.0",
"tailwindcss": "^3.0.7"
},
"devDependencies": {
Expand All @@ -32,4 +34,4 @@
"pug-cli": "^1.0.0-alpha6",
"rimraf": "^3.0.2"
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.42+42
version: 1.0.43+43

environment:
sdk: ^3.5.3
Expand Down
40 changes: 40 additions & 0 deletions whatsNew.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const OpenAI = require('openai');
const input = require('input');

const client = new OpenAI();

const template = `
<pl-PL>
Tutaj wpisz lub wklej informacje o wersji w tym języku: pl-PL
</pl-PL>
<de-DE>
Tutaj wpisz lub wklej informacje o wersji w tym języku: de-DE
</de-DE>
<en-US>
Tutaj wpisz lub wklej informacje o wersji w tym języku: en-US
</en-US>
<es-ES>
Tutaj wpisz lub wklej informacje o wersji w tym języku: es-ES
</es-ES>
<fr-FR>
Tutaj wpisz lub wklej informacje o wersji w tym języku: fr-FR
</fr-FR>
<it-IT>
Tutaj wpisz lub wklej informacje o wersji w tym języku: it-IT
</it-IT>
`;

async function main() {
const whatsNew = await input.text('What\'s new in this version?');
const prompt = `Fill following template with translations of text: "${whatsNew}".Output ONLY filled template\n\n Template:\n\n${template}.`;
const stream = await client.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: prompt }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
}

main();
Loading
Loading