Insert scheduled downtime infos from cloud calendar
Change-Id: I8e4524126c08c4b89298e29b4c17588ef3997b71
diff --git a/css/derekovecs.css b/css/derekovecs.css
index c175c3d..24236ad 100644
--- a/css/derekovecs.css
+++ b/css/derekovecs.css
@@ -394,3 +394,11 @@
margin-bottom: 1ex;
color: #657b83;
}
+dt {
+ float: left;
+ clear: left;
+ width: 25ex;
+ text-align: right;
+ font-weight: bold;
+ margin-right: 1ex;
+}
\ No newline at end of file
diff --git a/example.conf b/example.conf
index a68f5e3..cf8a324 100644
--- a/example.conf
+++ b/example.conf
@@ -16,6 +16,8 @@
vecs => "example-models/wpd19_10000/wpd19_10000.vecs"
},
+ downtime_calendar_url => "https://cloud.ids-mannheim.de/remote.php/dav/public-calendars/QfRCG4HriLcZJJRd?export",
+
# Piwik => {
# url => 'https://stats.ids-mannheim.de',
# token_auth => 'ad7609a669179c4ebca7c995342f7e12',
diff --git a/js/calendar-events.js b/js/calendar-events.js
new file mode 100644
index 0000000..c4fc9ee
--- /dev/null
+++ b/js/calendar-events.js
@@ -0,0 +1,72 @@
+async function getCalendar(icalUrl) {
+ const response = await fetch(icalUrl);
+ const data = await response.text();
+ return data;
+}
+
+function getDateFromjCal(jCal, event, name) {
+ const date = event.getFirstPropertyValue(name);
+ const vtimezone = jCal.getFirstSubcomponent('vtimezone');
+ if (vtimezone && moment(date.toJSDate()).utcOffset()) {
+ date.zone = new ICAL.Timezone(vtimezone);
+ }
+ var locale = window.navigator.userLanguage || window.navigator.language;
+ moment.locale(locale);
+ return moment.parseZone(date.toJSDate()).utcOffset(date.utcOffset() / 60)
+};
+
+function insertCalendarEvents(dlElement, icalUrl, maxAgeDays = 1) {
+
+ if (!icalUrl) {
+ return;
+ }
+
+ getCalendar(icalUrl).then(data => {
+ // console.log(data);
+ var jcalData = ICAL.parse(data);
+ var vcalendar = new ICAL.Component(jcalData);
+ ICAL.helpers.updateTimezones(vcalendar, ICAL.TimezoneService);
+ const element = dlElement;
+
+ var events = vcalendar.getAllSubcomponents('vevent');
+ var eventArray = [];
+ var eventKeys = [];
+ var now = moment();
+ events.forEach(event => {
+ var start = getDateFromjCal(vcalendar, event, 'dtstart');
+ if (now.diff(start, 'days') <= maxAgeDays) {
+ var key = event.getFirstPropertyValue("dtstart") + "-" + event.getFirstPropertyValue("dtend");
+ eventArray[key] = event;
+ eventKeys.push(key);
+ }
+ });
+ dlElement.replaceChildren();
+ if (eventKeys.length == 0) {
+ const dd = document.createElement('dd');
+ dd.appendChild(document.createTextNode("–"));
+ element.appendChild(dd);
+ return;
+ }
+ eventKeys.sort().reverse().forEach(key => {
+ var event = eventArray[key];
+ var summary = event.getFirstPropertyValue('summary');
+ var start = getDateFromjCal(vcalendar, event, 'dtstart');
+ var end = getDateFromjCal(vcalendar, event, 'dtend');
+ const dt = document.createElement('dt');
+ const time = document.createElement('time');
+ dt.setAttribute('class', 'maintenance');
+ const node = document.createTextNode(start.format('dddd, LL'));
+ time.appendChild(node);
+ time.setAttribute('datetime', start.format('YYYY-MM-DD'));
+ dt.appendChild(time);
+ element.appendChild(dt);
+ const dd = document.createElement('dd');
+ const description = document.createTextNode(start.format("HH:mm") + "-" + end.format("HH:mm") + ` ${summary}`);
+ dd.appendChild(description);
+ element.appendChild(dd);
+ });
+ }
+ ).catch(error => {
+ console.log(error);
+ });
+}
diff --git a/script/derekovecs-server b/script/derekovecs-server
index 16fed71..7525b0d 100755
--- a/script/derekovecs-server
+++ b/script/derekovecs-server
@@ -23,6 +23,8 @@
}
my $DEFAULT_NET = app->config->{w2v}->{net} // $DEFAULT_NET_NAME;
+my $DEFAULT_NET = app->config->{w2v}->{net} // $DEFAULT_NET_NAME;
+my $DOWNTIME_CALENDAR_URL = app->config->{downtime_calendar_url} // '';
app->static->paths->[0] = getcwd;
plugin 'Piwik';
@@ -343,7 +345,28 @@
if(!defined($word) || $word !~ /^\s*$/) {
$distantWords = getBiggestMergedDifferences();
}
- $c->render(template=>"index", title=>$title, word=>$word, distantWords=>$distantWords, cutoff=>$cutoff, no_nbs=>$no_nbs, no_iterations => $no_iterations, epsilon=> $epsilon, perplexity=> $perplexity, show_som=>$som, searchBaseVocabFirst=>$searchBaseVocabFirst, sort=>$sort, training_args=>$training_args, mergedEnd=> $mergedEnd, haveSProfiles=> $have_sprofiles, dedupe=> $dedupe, marked=>\%marked, lists=> \@lists, collocators=> $res->{syntagmatic});
+ $c->render(
+ template => "index",
+ title => $title,
+ word => $word,
+ distantWords => $distantWords,
+ cutoff => $cutoff,
+ no_nbs => $no_nbs,
+ no_iterations => $no_iterations,
+ epsilon => $epsilon,
+ perplexity => $perplexity,
+ show_som => $som,
+ searchBaseVocabFirst => $searchBaseVocabFirst,
+ sort => $sort,
+ training_args => $training_args,
+ mergedEnd => $mergedEnd,
+ haveSProfiles => $have_sprofiles,
+ dedupe => $dedupe,
+ marked => \%marked,
+ lists => \@lists,
+ collocators => $res->{syntagmatic},
+ downtime_calendar_url => $DOWNTIME_CALENDAR_URL
+ );
}
} => "paradigmaticAndSyntagmaticNbs";
diff --git a/templates/de/about.html.ep b/templates/de/about.html.ep
index 48356ca..8533e35 100644
--- a/templates/de/about.html.ep
+++ b/templates/de/about.html.ep
@@ -16,4 +16,8 @@
Es können sich jederzeit unangekündigt Dinge ändern und auch ein kompletter Ausfall über längere Zeit lässt sich nicht mit Sicherheit ausschließen.
Wenn Sie DeReKoVecs längerfristig für eigene Forschungen verwenden wollen, sprechen Sie uns bitte an.
</p>
+<h3>Geplante Ausfallzeiten</h3>
+<dl id="downtimes">
+ <dt></dt><dd>–</dd>
+</dl>
</html>
diff --git a/templates/en/about.html.ep b/templates/en/about.html.ep
index fd2fb7e..8492134 100644
--- a/templates/en/about.html.ep
+++ b/templates/en/about.html.ep
@@ -16,4 +16,8 @@
Things can change unannounced at any time and even a complete breakdown over a longer period of time cannot be excluded with certainty.
If you would like to use DeReKoVecs for your own research in the longer term, please contact us.
</p>
+<h3>Scheduled downtimes</h3>
+<dl id="downtimes">
+ <dt></dt><dd>–</dd>
+</dl>
</html>
diff --git a/templates/index.html.ep b/templates/index.html.ep
index d6c9ff2..4597a19 100644
--- a/templates/index.html.ep
+++ b/templates/index.html.ep
@@ -10,6 +10,14 @@
<script src = "https://cdn.datatables.net/fixedcolumns/3.2.5/js/dataTables.fixedColumns.min.js"></script>
<script src = "https://cdn.datatables.net/plug-ins/1.10.18/sorting/scientific.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML'></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/ical.js/1.5.0/ical.js"
+ integrity="sha512-UxWd2RMDGpYwYuDeU2Fs+nd51gw4ZLQY0D9wWZ3NuanNSk6QQmWCZ6C+rvI0lJ/b/nZtBQ8RVESA9DN9r65dUg=="
+ crossorigin="anonymous" referrerpolicy="no-referrer"></script>
+ <script
+ src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment-with-locales.min.js"
+ integrity="sha512-42PE0rd+wZ2hNXftlM78BSehIGzezNeQuzihiBCvUEB3CVxHvsShF86wBWwQORNxNINlBPuq7rG4WWhNiTVHFg=="
+ crossorigin="anonymous" referrerpolicy="no-referrer"></script>
+ <script src="js/calendar-events.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.18/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="/derekovecs/css/derekovecs.css">
<script
@@ -41,6 +49,7 @@
}
$(document).ready(function() {
+ insertCalendarEvents(document.getElementById('downtimes'), "<%= $downtime_calendar_url %>");
$('#firstable').hide();
//Set up a callback to hear back when MathJax is done rendering the equations