Skip to content

Commit

Permalink
Moved to new ranepa API
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolONEOfficial committed Jan 22, 2019
1 parent a9c763f commit c165f5a
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 75 deletions.
16 changes: 13 additions & 3 deletions lib/l10n/intl_messages.arb
@@ -1,5 +1,5 @@
{
"@@last_modified": "2018-12-25T04:02:46.803284",
"@@last_modified": "2019-01-23T00:16:40.239734",
"title": "RANEPA (Timetable)",
"@title": {
"type": "text",
Expand Down Expand Up @@ -95,7 +95,7 @@
"type": "text",
"placeholders": {}
},
"groupEconomics": "Economic theory",
"groupEconomics": "Economics",
"@groupEconomics": {
"type": "text",
"placeholders": {}
Expand All @@ -115,7 +115,17 @@
"type": "text",
"placeholders": {}
},
"economics": "Economics",
"discMath": "Discrete math",
"@discMath": {
"type": "text",
"placeholders": {}
},
"statMath": "Theory of probability and mathematical statistics",
"@statMath": {
"type": "text",
"placeholders": {}
},
"economics": "Economic theory",
"@economics": {
"type": "text",
"placeholders": {}
Expand Down
10 changes: 10 additions & 0 deletions lib/l10n/intl_ru.arb
Expand Up @@ -116,6 +116,16 @@
"type": "text",
"placeholders": {}
},
"discMath": "Дискретная математика",
"@discMath": {
"type": "text",
"placeholders": {}
},
"statMath": "Теория вероятностей и мат. статистика",
"@statMath": {
"type": "text",
"placeholders": {}
},
"economics": "Экономическая теория",
"@economics": {
"type": "text",
Expand Down
6 changes: 4 additions & 2 deletions lib/l10n/messages_messages.dart
Expand Up @@ -40,8 +40,9 @@ class MessageLookup extends MessageLookupByLibrary {
"computerGraphic" : MessageLookupByLibrary.simpleMessage("Computer Graphic"),
"credit" : MessageLookupByLibrary.simpleMessage("Reception of credit"),
"databases" : MessageLookupByLibrary.simpleMessage("Databases"),
"discMath" : MessageLookupByLibrary.simpleMessage("Discrete math"),
"documentManagementSupport" : MessageLookupByLibrary.simpleMessage("Document management support"),
"economics" : MessageLookupByLibrary.simpleMessage("Economics"),
"economics" : MessageLookupByLibrary.simpleMessage("Economic theory"),
"english" : MessageLookupByLibrary.simpleMessage("English"),
"ethics" : MessageLookupByLibrary.simpleMessage("Ethics"),
"exam" : MessageLookupByLibrary.simpleMessage("Exam"),
Expand All @@ -50,7 +51,7 @@ class MessageLookup extends MessageLookupByLibrary {
"friday" : MessageLookupByLibrary.simpleMessage("Fr"),
"geography" : MessageLookupByLibrary.simpleMessage("Geography"),
"groupDescription" : MessageLookupByLibrary.simpleMessage("Default timetable for the group/teacher"),
"groupEconomics" : MessageLookupByLibrary.simpleMessage("Economic theory"),
"groupEconomics" : MessageLookupByLibrary.simpleMessage("Economics"),
"groupInformatics" : MessageLookupByLibrary.simpleMessage("Informatics"),
"groupTitle" : MessageLookupByLibrary.simpleMessage("Group/teacher"),
"history" : MessageLookupByLibrary.simpleMessage("History"),
Expand Down Expand Up @@ -92,6 +93,7 @@ class MessageLookup extends MessageLookupByLibrary {
"socialStudies" : MessageLookupByLibrary.simpleMessage("Social Studies"),
"softwareDevelopment" : MessageLookupByLibrary.simpleMessage("Software Development"),
"speechCulture" : MessageLookupByLibrary.simpleMessage("Culture of Speech"),
"statMath" : MessageLookupByLibrary.simpleMessage("Theory of probability and mathematical statistics"),
"taxation" : MessageLookupByLibrary.simpleMessage("Taxation"),
"themeBlack" : MessageLookupByLibrary.simpleMessage("Black"),
"themeBlackRed" : MessageLookupByLibrary.simpleMessage("Black Red"),
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/messages_ru.dart
Expand Up @@ -40,6 +40,7 @@ class MessageLookup extends MessageLookupByLibrary {
"computerGraphic" : MessageLookupByLibrary.simpleMessage("Компьютерная графика"),
"credit" : MessageLookupByLibrary.simpleMessage("Прием зачета"),
"databases" : MessageLookupByLibrary.simpleMessage("Базы данных"),
"discMath" : MessageLookupByLibrary.simpleMessage("Дискретная математика"),
"documentManagementSupport" : MessageLookupByLibrary.simpleMessage("ДОУ (Документационное обеспечение управление)"),
"economics" : MessageLookupByLibrary.simpleMessage("Экономическая теория"),
"english" : MessageLookupByLibrary.simpleMessage("Английский язык"),
Expand Down Expand Up @@ -92,6 +93,7 @@ class MessageLookup extends MessageLookupByLibrary {
"socialStudies" : MessageLookupByLibrary.simpleMessage("Обществознание"),
"softwareDevelopment" : MessageLookupByLibrary.simpleMessage("Разработка ПО"),
"speechCulture" : MessageLookupByLibrary.simpleMessage("Культура речи"),
"statMath" : MessageLookupByLibrary.simpleMessage("Теория вероятностей и мат. статистика"),
"taxation" : MessageLookupByLibrary.simpleMessage("Налогообложение"),
"themeBlack" : MessageLookupByLibrary.simpleMessage("Черная"),
"themeBlackRed" : MessageLookupByLibrary.simpleMessage("Черно-красная"),
Expand Down
14 changes: 14 additions & 0 deletions lib/localizations.dart
Expand Up @@ -200,6 +200,20 @@ class AppLocalizations {
);
}

String get discMath {
return Intl.message(
'Discrete math',
name: 'discMath',
);
}

String get statMath {
return Intl.message(
'Theory of probability and mathematical statistics',
name: 'statMath',
);
}

String get economics {
return Intl.message(
'Economic theory',
Expand Down
4 changes: 2 additions & 2 deletions lib/search.dart
Expand Up @@ -20,9 +20,9 @@ final searchItemTypes = List<SearchItemType>.generate(
(index) {
switch (SearchItemTypeId.values[index]) {
case SearchItemTypeId.Teacher:
return SearchItemType(Icons.person, "Prep");
return SearchItemType(Icons.person, "teacher");
case SearchItemTypeId.Group:
return SearchItemType(Icons.group, "Group");
return SearchItemType(Icons.group, "group");
}
},
);
Expand Down
59 changes: 37 additions & 22 deletions lib/timeline_models.dart
Expand Up @@ -150,34 +150,34 @@ class LessonActions {
case LessonActionIds.Credit:
return LessonAction(
AppLocalizations.of(context).credit, <List<String>>[
<String>["прием", "зачет"]
//<String>["прием", "зачет"] TODO: exam etc
]);
case LessonActionIds.Exam:
return LessonAction(
AppLocalizations.of(context).exam, <List<String>>[
<String>["прием", "экзамен"]
//<String>["прием", "экзамен"]
]);
case LessonActionIds.ExamConsultation:
return LessonAction(
AppLocalizations.of(context).examConsultation,
<List<String>>[
<String>["консульт", "экзамен"]
//<String>["консульт", "экзамен"]
]);
case LessonActionIds.Practice:
return LessonAction(
AppLocalizations.of(context).practice, <List<String>>[
<String>["практ"]
<String>["прак"]
]);
case LessonActionIds.ReceptionExamination:
return LessonAction(
AppLocalizations.of(context).receptionExamination,
<List<String>>[
<String>["защит", "прием"]
//<String>["защит", "прием"]
]);
case LessonActionIds.Lecture:
return LessonAction(
AppLocalizations.of(context).lecture, <List<String>>[
<String>["лекция"]
<String>["лек"]
]);
}
},
Expand All @@ -193,13 +193,6 @@ enum LessonActionIds {
Credit,
}

String parseLessonTitle(String str) {
final openBracketIndex = str.indexOf('('),
title = str.substring(
0, openBracketIndex != -1 ? openBracketIndex : str.length - 1);
return title[0].toUpperCase() + title.substring(1);
}

@JsonSerializable(nullable: false)
class LessonModel extends Findable {
String fullTitle;
Expand Down Expand Up @@ -235,30 +228,34 @@ class LessonModel extends Findable {

Map<String, dynamic> toJson() => _$LessonModelToJson(this);

factory LessonModel.fromString(BuildContext context, String str) {
final lowerStr = str.toLowerCase();

factory LessonModel.build(
BuildContext context,
String subject,
String type,
) {
LessonModel model;

final lowerSubject = subject.toLowerCase();
for (final mLesson in Lessons(context).lessons) {
if (mLesson.find(lowerStr)) {
if (mLesson.find(lowerSubject)) {
model = mLesson.copy();
break;
}
}

if (model == null)
model = LessonModel._(
parseLessonTitle(lowerStr), TimetableIcons.unknownLesson.codePoint);
model = LessonModel._(subject, TimetableIcons.unknownLesson.codePoint);

model.fullTitle =
str.substring(0, str.indexOf(')')).replaceFirst('(', '\n');
final lowerType = type.toLowerCase();
for (final mType in LessonActions(context).actions) {
if (mType.find(lowerStr)) {
if (mType.find(lowerType)) {
model.action = mType;
break;
}
}
if (model.action == null)
model.action = LessonAction(type, <List<String>>[]);
model.fullTitle = "$subject (${model.action.title})\n";

debugPrint("model type: ${model.action?.title}");

Expand All @@ -268,6 +265,8 @@ class LessonModel extends Findable {

enum LessonIds {
math,
discMath,
statMath,
economics,
informationTheory,
philosophy,
Expand Down Expand Up @@ -342,6 +341,22 @@ class Lessons {
<String>["математик"]
],
);
case LessonIds.discMath:
return LessonModel._(
AppLocalizations.of(context).discMath,
TimetableIcons.math.codePoint,
<List<String>>[
<String>["дискрет", "математ"]
],
);
case LessonIds.statMath:
return LessonModel._(
AppLocalizations.of(context).statMath,
TimetableIcons.math.codePoint,
<List<String>>[
<String>["статистик", "математ"]
],
);
case LessonIds.economics:
return LessonModel._(
AppLocalizations.of(context).economics,
Expand Down
71 changes: 25 additions & 46 deletions lib/timetable.dart
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:io';

import 'package:android_intent/android_intent.dart';
Expand All @@ -17,16 +18,6 @@ import 'package:ranepa_timetable/timeline_models.dart';
import 'package:ranepa_timetable/widget_templates.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tuple/tuple.dart';
import 'package:xml/xml.dart' as xml;

enum TimetableResponseIndexes {
Date,
TimeStart,
TimeFinish,
Name,
Room,
Group,
}

class Timetable extends StatelessWidget {
final Drawer drawer;
Expand Down Expand Up @@ -113,21 +104,14 @@ class Timetable extends StatelessWidget {
debugPrint("ended get timetable");
}

static String formatDateTime(DateTime dt) =>
"${dt.day}.${dt.month}.${dt.year}";

static Future<http.Response> _buildHttpRequest(
SearchItem searchItem, DateTime from, DateTime to) =>
http.post('http://test.ranhigs-nn.ru/api/WebService.asmx',
headers: {'Content-Type': 'text/xml; charset=utf-8'}, body: '''
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetRasp${searchItemTypes[searchItem.typeId.index].getStr} xmlns="http://tempuri.org/">
<d1>${from.toIso8601String()}</d1>
<d2>${to.toIso8601String()}</d2>
<id>${searchItem.id}</id>
</GetRasp${searchItemTypes[searchItem.typeId.index].getStr}>
</soap:Body>
</soap:Envelope>
''');
http.get('http://services.niu.ranepa.ru/API/public/'
'${searchItemTypes[searchItem.typeId.index].getStr}/${searchItem.id}'
'/schedule/${formatDateTime(from)}/${formatDateTime(to)}');

static Future<void> loadTimetable(
BuildContext context,
Expand All @@ -137,31 +121,18 @@ class Timetable extends StatelessWidget {
SharedPreferences prefs, [
bool updateDb = true,
]) async {
if(!await _checkInternetConnection())
return;
if (!await _checkInternetConnection()) return;

final response = await _buildHttpRequest(searchItem, from, to);

debugPrint("http load end. starting parse request..");

final itemArr = xml
.parse(response.body)
.children[1]
.firstChild
.firstChild
.firstChild
.children;
final itemArr = json.decode(response.body);

var mDate = from.subtract(Duration(days: 1));
final _startDayId = timetable.keys.length;
for (final mItem in itemArr) {
final mItemTimeStart =
mItem.children[TimetableResponseIndexes.TimeStart.index].text;
final mItemTimeFinish =
mItem.children[TimetableResponseIndexes.TimeFinish.index].text;
final mItemDate = DateTime.parse(
mItem.children[TimetableResponseIndexes.Date.index].text);

final mItemDate = DateTime.parse(mItem["xdt"]);
while (mItemDate != mDate) {
mDate = mDate.add(Duration(days: 1));
// skip sunday
Expand All @@ -170,6 +141,9 @@ class Timetable extends StatelessWidget {
}
}

final mItemTimeStart = mItem["nf"];
final mItemTimeFinish = mItem["kf"];

final mLesson = TimelineModel(
date: mItemDate,
start: TimeOfDay(
Expand All @@ -182,14 +156,18 @@ class Timetable extends StatelessWidget {
mItemTimeFinish.substring(0, mItemTimeFinish.length - 3)),
minute: int.parse(mItemTimeFinish.substring(
mItemTimeFinish.length - 2, mItemTimeFinish.length))),
room: RoomModel.fromString(
mItem.children[TimetableResponseIndexes.Room.index].text),
group: mItem.children[TimetableResponseIndexes.Group.index].text,
lesson: LessonModel.fromString(
context, mItem.children[TimetableResponseIndexes.Name.index].text),
room: RoomModel.fromString(mItem["number"]),
group: searchItem.typeId == SearchItemTypeId.Teacher
? mItem["group"]
: searchItem.title,
lesson: LessonModel.build(
context,
mItem["subject"],
mItem["type"],
),
teacher: TeacherModel.fromString(
searchItem.typeId == SearchItemTypeId.Group
? mItem.children[TimetableResponseIndexes.Name.index].text
? mItem["teacher"]
: searchItem.title),
);

Expand Down Expand Up @@ -410,7 +388,8 @@ class Timetable extends StatelessWidget {
context,
future: _checkInternetConnection(),
builder: (context, internetConn) {
if (!internetConn.data && (!Platform.isAndroid || !ssSearchItem.data.item1))
if (!internetConn.data &&
(!Platform.isAndroid || !ssSearchItem.data.item1))
return WidgetTemplates.buildNetworkErrorNotification(
context);
return WidgetTemplates.buildFutureBuilder(
Expand Down

0 comments on commit c165f5a

Please sign in to comment.