Commit 38df79e3 authored by Romain Courteaud's avatar Romain Courteaud

erp5_web_but: parse rugby json

parent 5f573c30
...@@ -283,3 +283,7 @@ body > main > table thead th { ...@@ -283,3 +283,7 @@ body > main > table thead th {
min-width: 10em; min-width: 10em;
text-transform: uppercase; text-transform: uppercase;
} }
table {
text-align: center;
}
\ No newline at end of file
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>968.15468.48654.57804</string> </value> <value> <string>1010.49822.40856.18739</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1529064254.49</float> <float>1693772961.07</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
<!DOCTYPE html> <!DOCTYPE html>
<html manifest="world_cup_2018.appcache"> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
...@@ -45,8 +45,8 @@ ...@@ -45,8 +45,8 @@
{{/if}} {{/if}}
</li>{{/each}}</ul> </li>{{/each}}</ul>
<button type="button" data-wc2018="renderExport">Share!</button> <button type="button" data-wc2018="renderExport">Share!</button>
<button type="button" data-wc2018="renderImport">Import</button> <!--button type="button" data-wc2018="renderImport">Import</button-->
<button type="button" data-wc2018="renderResult">Result</button> <!--button type="button" data-wc2018="renderResult">Result</button-->
</script> </script>
<script id="share_template" type="text/x-handlebars-template"> <script id="share_template" type="text/x-handlebars-template">
...@@ -73,21 +73,22 @@ ...@@ -73,21 +73,22 @@
<script id="day_form_template" type="text/x-handlebars-template"> <script id="day_form_template" type="text/x-handlebars-template">
<form data-wc2018="submitBet"> <form data-wc2018="submitBet">
<h2>{{day_string}}</h2> <h2>{{day_string}}</h2>
<ul> <table>
{{#each match_list}}<li> <tr><td></td><td></td><td>Draw</td><td></td><td></td></tr>
<!--input type="radio" name="couscous" id="couscous_1" required /> {{#each match_list}}<tr>
<label for="couscous_1">Home</label--> <td>
<label for="{{home_bet_reference}}">{{home_bet_title}}</label> <label for="{{match_id}}winnerChoice1">{{home_bet_title}}</label>
<input required type="integer" name="{{home_bet_reference}}" </td><td>
id="{{home_bet_reference}}" value="{{home_bet}}"></input> <input type="radio" id="{{match_id}}winnerChoice1" name="{{match_id}}" value="home" {{home_checked}}/>
/ </td><td>
<input required type="integer" name="{{away_bet_reference}}" <input type="radio" id="{{match_id}}winnerChoice2" name="{{match_id}}" value="draw" {{draw_checked}} />
id="{{away_bet_reference}}" value="{{away_bet}}"></input> </td><td>
<label for="{{away_bet_reference}}">{{away_bet_title}}</label> <input type="radio" id="{{match_id}}winnerChoice3" name="{{match_id}}" value="away" {{away_checked}}/>
<!--input type="radio" name="couscous" id="couscous_2" required /> </td><td>
<label for="couscous_2">Away</label--> <label for="{{match_id}}winnerChoice3">{{away_bet_title}}</label>
</li>{{/each}} </td>
</ul> </tr>{{/each}}
</table>
<input type="submit" value="Save"></input> <input type="submit" value="Save"></input>
</form> </form>
</script> </script>
...@@ -97,8 +98,8 @@ ...@@ -97,8 +98,8 @@
<body> <body>
<header> <header>
<h1>Fifa World Cup</h1> <h1>Rugby World Cup</h1>
<p>Russia 2018</p> <p>France 2023</p>
</header> </header>
<main></main> <main></main>
</body> </body>
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>968.15868.5231.7987</string> </value> <value> <string>1010.58506.47731.21435</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1529087777.33</float> <float>1693772860.24</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
team_dict = {}; team_dict = {};
// Parse teams // Parse teams
/*
for (i = this._parser.teams.length; i > 0; i -= 1) { for (i = this._parser.teams.length; i > 0; i -= 1) {
tmp = this._parser.teams[i - 1]; tmp = this._parser.teams[i - 1];
result_list.push({ result_list.push({
...@@ -49,8 +50,34 @@ ...@@ -49,8 +50,34 @@
}); });
team_dict[tmp.id] = tmp.name; team_dict[tmp.id] = tmp.name;
} }
*/
// Parse groups // Parse groups
for (i = 0; i < this._parser.matches.length; i += 1) {
tmp = this._parser.matches[i];
if (tmp.eventPhaseId.type !== 'Pool') {
continue;
}
result_list.push({
id: 'match_' + (i + 1),
value: {},
doc: {
portal_type: 'World Cup 2023 Match',
match_id: tmp.matchId,
group_match: true,
start_date: tmp.time.label,
home_team: tmp.teams[0].id,
home_team_title: tmp.teams[0].name,
home_result: tmp.scores[0],
away_team: tmp.teams[1].id,
away_team_title: tmp.teams[1].name,
away_result: tmp.scores[1],
finished: tmp.status !== "U",
title: tmp.teams[0].name + ' / ' + tmp.teams[1].name
}
});
}
/*
for (key in this._parser.groups) { for (key in this._parser.groups) {
if (this._parser.groups.hasOwnProperty(key)) { if (this._parser.groups.hasOwnProperty(key)) {
// Group document // Group document
...@@ -64,28 +91,10 @@ ...@@ -64,28 +91,10 @@
}); });
// Match documents // Match documents
for (i = this._parser.groups[key].matches.length; i > 0; i -= 1) { for (i = this._parser.groups[key].matches.length; i > 0; i -= 1) {
tmp = this._parser.groups[key].matches[i - 1];
result_list.push({
id: 'match_' + tmp.name,
value: {},
doc: {
portal_type: 'World Cup 2018 Match',
group_match: true,
start_date: tmp.date,
home_team: tmp.home_team,
home_team_title: team_dict[tmp.home_team],
home_result: tmp.home_result,
away_team: tmp.away_team,
away_team_title: team_dict[tmp.away_team],
away_result: tmp.away_result,
finished: tmp.finished,
title: team_dict[tmp.home_team] + ' / ' + team_dict[tmp.away_team]
}
});
} }
} }
} }
*/
/* /*
// Parse knockout // Parse knockout
for (key in this._parser.knockout) { for (key in this._parser.knockout) {
...@@ -131,10 +140,7 @@ ...@@ -131,10 +140,7 @@
return storage._parser; return storage._parser;
}); });
} }
return new RSVP.Queue() return new RSVP.Queue(storage._parser);
.push(function () {
return storage._parser;
});
} }
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
...@@ -195,9 +201,14 @@ ...@@ -195,9 +201,14 @@
len = form.elements.length; len = form.elements.length;
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
if (form.elements[i].hasAttribute('name')) { if (form.elements[i].hasAttribute('name')) {
if (((form.elements[i].type === 'radio') &&
(form.elements[i].checked)) ||
(form.elements[i].type !== 'radio')) {
form_data[form.elements[i].name] = form.elements[i].value; form_data[form.elements[i].name] = form.elements[i].value;
} }
} }
}
return form_data; return form_data;
} }
...@@ -229,8 +240,8 @@ ...@@ -229,8 +240,8 @@
}, },
remote_sub_storage: { remote_sub_storage: {
type: 'world_cup_data', type: 'world_cup_data',
// document_id: 'world_cup_2018_data.json', document_id: './world_cup_2018_data.json',
document_id: 'https://raw.githubusercontent.com/lsv/' + document_idXXX: 'https://raw.githubusercontent.com/lsv/' +
'fifa-worldcup-2018/master/data.json', 'fifa-worldcup-2018/master/data.json',
attachment_id: 'enclosure', attachment_id: 'enclosure',
sub_storage: { sub_storage: {
...@@ -302,7 +313,7 @@ ...@@ -302,7 +313,7 @@
.declareMethod('renderCalendar', function renderLauncher() { .declareMethod('renderCalendar', function renderLauncher() {
var gadget = this; var gadget = this;
return gadget._storage.allDocs({ return gadget._storage.allDocs({
query: 'portal_type:"World Cup 2018 Match"', query: 'portal_type:"World Cup 2023 Match"',
select_list: ['portal_type', 'start_date', 'home_team', 'title'], select_list: ['portal_type', 'start_date', 'home_team', 'title'],
sort_on: [['start_date', 'ascending'], ['title', 'ascending']] sort_on: [['start_date', 'ascending'], ['title', 'ascending']]
}) })
...@@ -355,10 +366,10 @@ ...@@ -355,10 +366,10 @@
.push(function (result) { .push(function (result) {
bet = result; bet = result;
return gadget._storage.allDocs({ return gadget._storage.allDocs({
query: 'portal_type:"World Cup 2018 Match" AND ' + query: 'portal_type:"World Cup 2023 Match" AND ' +
'start_date:"' + day_query + '%"', 'start_date:"' + day_query + '"',
select_list: ['portal_type', 'start_date', 'title', select_list: ['portal_type', 'start_date', 'title',
'home_team_title', 'away_team_title'], 'home_team_title', 'away_team_title', 'match_id'],
sort_on: [['start_date', 'ascending'], ['title', 'ascending']] sort_on: [['start_date', 'ascending'], ['title', 'ascending']]
}); });
}) })
...@@ -367,13 +378,16 @@ ...@@ -367,13 +378,16 @@
length = result.data.rows.length, length = result.data.rows.length,
match_list = [], match_list = [],
match; match;
if (length === 0) {
throw new Error("No result for date " + day_query);
}
for (i = 0; i < length; i += 1) { for (i = 0; i < length; i += 1) {
match = result.data.rows[i].value; match = result.data.rows[i].value;
match.home_bet_reference = result.data.rows[i].id + '_A'; match.bet = bet[match.match_id] || 'draw';
match.away_bet_reference = result.data.rows[i].id + '_B'; match.home_checked = match.bet === 'home' ? 'checked' : '';
// init to 0 match.draw_checked = match.bet === 'draw' ? 'checked' : '';
match.home_bet = bet[match.home_bet_reference] || 0; match.away_checked = match.bet === 'away' ? 'checked' : '';
match.away_bet = bet[match.away_bet_reference] || 0;
match.home_bet_title = match.home_team_title; match.home_bet_title = match.home_team_title;
match.away_bet_title = match.away_team_title; match.away_bet_title = match.away_team_title;
match_list.push(result.data.rows[i].value); match_list.push(result.data.rows[i].value);
...@@ -389,32 +403,34 @@ ...@@ -389,32 +403,34 @@
var gadget = this, var gadget = this,
match_list; match_list;
return gadget._storage.allDocs({ return gadget._storage.allDocs({
query: 'portal_type:"World Cup 2018 Match" AND ' + query: 'portal_type:"World Cup 2023 Match" AND ' +
'group_match: true', 'group_match: true',
select_list: ['start_date'], select_list: ['start_date', 'match_id'],
sort_on: [['start_date', 'ascending'], ['title', 'ascending']] sort_on: [['match_id', 'ascending']]
}) })
.push(function (result) { .push(function (result) {
match_list = result.data.rows; match_list = result.data.rows;
return gadget.getBet(); return gadget.getBet();
}) })
.push(function (doc) { .push(function (bet) {
var i, var i,
j,
result = '', result = '',
key, score,
suffix_list = ['_A', '_B']; key;
for (i = 0; i < match_list.length; i += 1) { for (i = 0; i < match_list.length; i += 1) {
for (j = 0; j < suffix_list.length; j += 1) { key = match_list[i].value.match_id;
key = 'match_' + (i + 1) + suffix_list[j]; if (!bet.hasOwnProperty(key)) {
if ((!doc.hasOwnProperty(key)) ||
(parseInt(doc[key], 10) > 15)) {
// Bet between 0 and 15
return gadget.renderCard(match_list[i].value return gadget.renderCard(match_list[i].value
.start_date.substr(0, 10)); .start_date.substr(0, 10));
} }
result += parseInt(doc[key], 10).toString(16); if (bet[key] === 'draw') {
score = '0';
} else if (bet[key] === 'home') {
score = '1';
} else {
score = '2';
} }
result += parseInt(score, 10).toString(16);
} }
gadget.element.querySelector('main').innerHTML = share_template({ gadget.element.querySelector('main').innerHTML = share_template({
code: LZString.compressToBase64(result) code: LZString.compressToBase64(result)
...@@ -423,7 +439,7 @@ ...@@ -423,7 +439,7 @@
}) })
.declareMethod('renderImport', function renderExport() { .declareMethod('renderImport', function renderImport() {
var gadget = this; var gadget = this;
return gadget.getCodeDict() return gadget.getCodeDict()
.push(function (code_dict) { .push(function (code_dict) {
...@@ -443,17 +459,18 @@ ...@@ -443,17 +459,18 @@
var gadget = this, var gadget = this,
match_list; match_list;
return gadget._storage.allDocs({ return gadget._storage.allDocs({
query: 'portal_type:"World Cup 2018 Match" AND finished:true AND ' + query: 'portal_type:"World Cup 2023 Match" AND finished:true AND ' +
'group_match: true', 'group_match: true',
select_list: ['start_date', 'home_result', 'away_result', select_list: ['start_date', 'home_result', 'away_result',
'home_team_title', 'away_team_title', 'title'], 'home_team_title', 'away_team_title', 'title'],
sort_on: [['start_date', 'ascending'], ['title', 'ascending']] sort_on: [['match_id', 'ascending']]
}) })
.push(function (result) { .push(function (result) {
match_list = result.data.rows; match_list = result.data.rows;
return gadget.getCodeDict(); return gadget.getCodeDict();
}) })
.push(function (code_dict) { .push(function (code_dict) {
console.log(code_dict);
// First, decode all codes // First, decode all codes
var key, var key,
i, i,
......
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>968.19633.6812.24251</string> </value> <value> <string>1010.58492.51761.29798</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -256,7 +256,7 @@ ...@@ -256,7 +256,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1529314173.15</float> <float>1693771993.21</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>World Cup 2018</string> </value> <value> <string>World Cup 2023</string> </value>
</item> </item>
<item> <item>
<key> <string>visible</string> </key> <key> <string>visible</string> </key>
...@@ -428,7 +428,7 @@ ...@@ -428,7 +428,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>968.59.40410.23688</string> </value> <value> <string>1010.49822.40856.18739</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -448,7 +448,7 @@ ...@@ -448,7 +448,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1529060918.21</float> <float>1693252020.78</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment