Compare commits

..

No commits in common. "016622c7af7e338d98af1dabf05236a536d8133d" and "86bcec6b29170c9508b64bb8b18defbff9bc4fee" have entirely different histories.

5 changed files with 142 additions and 152 deletions

View File

@ -15,20 +15,16 @@ OSM_CACHE_DIR = Path(cache_dir_string)
import logging import logging
# if we are in a debug session, set verbose and rich logging import yaml
if os.getenv('DEBUG', False):
from rich.logging import RichHandler
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[RichHandler()]
)
else:
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
)
LOGGING_CONFIG = LOCATION_PREFIX / 'log_config.yaml'
config = yaml.safe_load(LOGGING_CONFIG.read_text())
logging.config.dictConfig(config)
# if we are in a debug session, set the log level to debug
if os.getenv('DEBUG', False):
logging.getLogger().setLevel(logging.DEBUG)
MEMCACHED_HOST_PATH = os.getenv('MEMCACHED_HOST_PATH', None) MEMCACHED_HOST_PATH = os.getenv('MEMCACHED_HOST_PATH', None)
if MEMCACHED_HOST_PATH == "none": if MEMCACHED_HOST_PATH == "none":

View File

@ -0,0 +1,35 @@
version: 1
disable_existing_loggers: False
formatters:
simple:
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
handlers:
console:
class: rich.logging.RichHandler
formatter: simple
width: 255
# access:
# class: logging.FileHandler
# filename: logs/access.log
# level: INFO
# formatter: simple
loggers:
uvicorn.error:
level: INFO
handlers:
- console
propagate: no
# uvicorn.access:
# level: INFO
# handlers:
# - access
# propagate: no
root:
level: INFO
handlers:
- console
propagate: yes

View File

@ -9,9 +9,6 @@ class ProfilePage extends StatefulWidget {
} }
class _ProfilePageState extends State<ProfilePage> { class _ProfilePageState extends State<ProfilePage> {
Future<UserPreferences> _prefs = loadUserPreferences();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ListView( return ListView(
@ -27,82 +24,66 @@ class _ProfilePageState extends State<ProfilePage> {
child: Text('Curious traveler', style: TextStyle(fontSize: 24)) child: Text('Curious traveler', style: TextStyle(fontSize: 24))
), ),
Divider(indent: 25, endIndent: 25, height: 50), Padding(padding: EdgeInsets.all(10)),
Divider(indent: 25, endIndent: 25),
Padding(padding: EdgeInsets.all(10)),
Center( Padding(
child: Padding(
padding: EdgeInsets.only(left: 10, right: 10, top: 0, bottom: 10), padding: EdgeInsets.only(left: 10, right: 10, top: 0, bottom: 10),
child: Text('For a tailored experience, please rate your discovery preferences.', style: TextStyle(fontSize: 18)) child: Text('Please rate your personal preferences so that we can taylor your experience.', style: TextStyle(fontSize: 18))
),
), ),
FutureBuilder(future: _prefs, builder: futureSliders) // Now the sliders
ImportanceSliders()
] ]
); );
} }
Widget futureSliders(BuildContext context, AsyncSnapshot<UserPreferences> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
UserPreferences prefs = snapshot.data!;
return Column(
children: [
PreferenceSliders(prefs: [prefs.maxTime, prefs.maxDetour]),
Divider(indent: 25, endIndent: 25, height: 50),
PreferenceSliders(prefs: [prefs.sightseeing, prefs.shopping, prefs.nature])
]
);
} else {
return CircularProgressIndicator();
}
}
} }
class PreferenceSliders extends StatefulWidget { class ImportanceSliders extends StatefulWidget {
final List<SinglePreference> prefs;
PreferenceSliders({required this.prefs});
@override @override
State<PreferenceSliders> createState() => _PreferenceSlidersState(); State<ImportanceSliders> createState() => _ImportanceSlidersState();
} }
class _PreferenceSlidersState extends State<PreferenceSliders> { class _ImportanceSlidersState extends State<ImportanceSliders> {
@override UserPreferences _prefs = UserPreferences();
Widget build(BuildContext context) {
List<Card> _createSliders() {
List<Card> sliders = []; List<Card> sliders = [];
for (SinglePreference pref in widget.prefs) { for (SinglePreference pref in _prefs.preferences) {
sliders.add( sliders.add(Card(
Card(
child: ListTile( child: ListTile(
leading: pref.icon, leading: pref.icon,
title: Text(pref.name), title: Text(pref.name),
subtitle: Slider( subtitle: Slider(
value: pref.value.toDouble(), value: pref.value.toDouble(),
min: pref.minVal.toDouble(), min: 0,
max: pref.maxVal.toDouble(), max: 10,
divisions: pref.maxVal - pref.minVal, divisions: 10,
label: pref.value.toString(), label: pref.value.toString(),
onChanged: (double newValue) { onChanged: (double newValue) {
setState(() { setState(() {
pref.value = newValue.toInt(); pref.value = newValue.toInt();
pref.save(); _prefs.save();
}); });
}, },
) )
), ),
margin: const EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 0), margin: const EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 0),
shadowColor: Colors.grey, shadowColor: Colors.grey,
) ));
); }
return sliders;
} }
return Column( @override
children: sliders); Widget build(BuildContext context) {
}
}
return Column(children: _createSliders());
}
}

View File

@ -3,102 +3,80 @@ import 'package:shared_preferences/shared_preferences.dart';
class SinglePreference { class SinglePreference {
String slug;
String name; String name;
String description; String description;
int value; int value;
int minVal;
int maxVal;
Icon icon; Icon icon;
String key;
SinglePreference({ SinglePreference({
required this.slug,
required this.name, required this.name,
required this.description, required this.description,
required this.value, required this.value,
required this.icon, required this.icon,
this.minVal = 0, required this.key,
this.maxVal = 5,
}); });
void save() async {
SharedPreferences sharedPrefs = await SharedPreferences.getInstance();
sharedPrefs.setInt('pref_$slug', value);
}
void load() async {
SharedPreferences sharedPrefs = await SharedPreferences.getInstance();
value = sharedPrefs.getInt('pref_$slug') ?? minVal;
}
} }
class UserPreferences { class UserPreferences {
SinglePreference sightseeing = SinglePreference( List<SinglePreference> preferences = [
SinglePreference(
name: "Sightseeing", name: "Sightseeing",
slug: "sightseeing",
description: "How much do you like sightseeing?", description: "How much do you like sightseeing?",
value: 0, value: 0,
icon: Icon(Icons.church), icon: Icon(Icons.church),
); key: "sightseeing",
SinglePreference shopping = SinglePreference( ),
SinglePreference(
name: "Shopping", name: "Shopping",
slug: "shopping",
description: "How much do you like shopping?", description: "How much do you like shopping?",
value: 0, value: 0,
icon: Icon(Icons.shopping_bag), icon: Icon(Icons.shopping_bag),
); key: "shopping",
SinglePreference nature = SinglePreference( ),
SinglePreference(
name: "Foods & Drinks",
description: "How much do you like eating?",
value: 0,
icon: Icon(Icons.restaurant),
key: "eating",
),
SinglePreference(
name: "Nightlife",
description: "How much do you like nightlife?",
value: 0,
icon: Icon(Icons.wine_bar),
key: "nightlife",
),
SinglePreference(
name: "Nature", name: "Nature",
slug: "nature",
description: "How much do you like nature?", description: "How much do you like nature?",
value: 0, value: 0,
icon: Icon(Icons.landscape), icon: Icon(Icons.landscape),
); key: "nature",
),
SinglePreference maxTime = SinglePreference( SinglePreference(
name: "Trip duration", name: "Culture",
slug: "duration", description: "How much do you like culture?",
description: "How long do you want your trip to be?",
value: 30,
minVal: 30,
maxVal: 720,
icon: Icon(Icons.timer),
);
SinglePreference maxDetour = SinglePreference(
name: "Trip detours",
slug: "detours",
description: "Are you okay with roaming even if makes the trip longer?",
value: 0, value: 0,
maxVal: 30, icon: Icon(Icons.palette),
icon: Icon(Icons.loupe_sharp), key: "culture",
); ),
];
void save() async {
Future<void> load() async { SharedPreferences sharedPrefs = await SharedPreferences.getInstance();
for (SinglePreference pref in [sightseeing, shopping, nature, maxTime, maxDetour]) { for (SinglePreference pref in preferences) {
pref.load(); sharedPrefs.setInt(pref.key, pref.value);
} }
} }
String toJson() { void load() async {
// This is "opinionated" JSON, corresponding to the backend's expectations SharedPreferences sharedPrefs = await SharedPreferences.getInstance();
return ''' for (SinglePreference pref in preferences) {
{ pref.value = sharedPrefs.getInt(pref.key) ?? 0;
"sightseeing": {"type": "sightseeing", "score": ${sightseeing.value}},
"shopping": {"type": "shopping", "score": ${shopping.value}},
"nature": {"type": "nature", "score": ${nature.value}},
"max_time_minutes": ${maxTime.value},
"detour_tolerance_minute": ${maxDetour.value}
}
''';
} }
} }
Future<UserPreferences> loadUserPreferences() async {
UserPreferences prefs = UserPreferences();
await prefs.load();
return prefs;
} }

View File

@ -28,8 +28,8 @@ Future<Trip> fetchTrip(
final response = await dio.post( final response = await dio.post(
"/trip/new", "/trip/new",
data: { data: {
'preferences': preferences.toJson(), // 'preferences': preferences.toJson(),
'start': startPoint 'start': [48,2.3]
} }
); );