how to display the team with the most consecutive “win”. in an epl match neo4j
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This question is a follow up to the answer given here Finding the most consecutive wins in a rugby league
by @cybersam
My program is for an EPL match.
but my database structure is exactly the same
my problem is this doesn't give the required output.
i tried this on my database and it gives the output as - Manchester united with 14 consecutive wins.
its meant to be 18.
This is the data set
and the tried code
Round,Date,Team 1,FT,HT,Team 2
1,(Fri) 11 Aug 2017 (32),Arsenal FC,4-3,2-2,Leicester City FC
MATCH (t:Team)<-[r]-(g:Match)-[r2]->(t2)
WITH t, r.Ftaway_goal > r2.Fthome_goal AS isWin ORDER BY g.Date, g.Round
RETURN t, REDUCE(s = {max: 0, c: 0, prev:false}, w IN COLLECT(isWin) |
CASE WHEN w
THEN {
c: CASE WHEN s.prev THEN s.c+1 ELSE 1 END,
max: CASE WHEN s.max <= s.c
THEN CASE WHEN s.prev
THEN s.c+1
ELSE CASE WHEN s.max = 0 THEN 1 ELSE s.max END END
ELSE s.max END,
prev: w}
ELSE {c: 0, max: s.max, prev: w} END).max AS maxConsecutiveWins
order by maxConsecutiveWins DESC
limit 1
The case part of the code i understand but i cant seem to figure out why some wins aren't being checked against it.
initially i thought it was an issue with it only counting the away_team matches but it isn't.
Please help. thanks
neo4j cypher
add a comment |
This question is a follow up to the answer given here Finding the most consecutive wins in a rugby league
by @cybersam
My program is for an EPL match.
but my database structure is exactly the same
my problem is this doesn't give the required output.
i tried this on my database and it gives the output as - Manchester united with 14 consecutive wins.
its meant to be 18.
This is the data set
and the tried code
Round,Date,Team 1,FT,HT,Team 2
1,(Fri) 11 Aug 2017 (32),Arsenal FC,4-3,2-2,Leicester City FC
MATCH (t:Team)<-[r]-(g:Match)-[r2]->(t2)
WITH t, r.Ftaway_goal > r2.Fthome_goal AS isWin ORDER BY g.Date, g.Round
RETURN t, REDUCE(s = {max: 0, c: 0, prev:false}, w IN COLLECT(isWin) |
CASE WHEN w
THEN {
c: CASE WHEN s.prev THEN s.c+1 ELSE 1 END,
max: CASE WHEN s.max <= s.c
THEN CASE WHEN s.prev
THEN s.c+1
ELSE CASE WHEN s.max = 0 THEN 1 ELSE s.max END END
ELSE s.max END,
prev: w}
ELSE {c: 0, max: s.max, prev: w} END).max AS maxConsecutiveWins
order by maxConsecutiveWins DESC
limit 1
The case part of the code i understand but i cant seem to figure out why some wins aren't being checked against it.
initially i thought it was an issue with it only counting the away_team matches but it isn't.
Please help. thanks
neo4j cypher
add a comment |
This question is a follow up to the answer given here Finding the most consecutive wins in a rugby league
by @cybersam
My program is for an EPL match.
but my database structure is exactly the same
my problem is this doesn't give the required output.
i tried this on my database and it gives the output as - Manchester united with 14 consecutive wins.
its meant to be 18.
This is the data set
and the tried code
Round,Date,Team 1,FT,HT,Team 2
1,(Fri) 11 Aug 2017 (32),Arsenal FC,4-3,2-2,Leicester City FC
MATCH (t:Team)<-[r]-(g:Match)-[r2]->(t2)
WITH t, r.Ftaway_goal > r2.Fthome_goal AS isWin ORDER BY g.Date, g.Round
RETURN t, REDUCE(s = {max: 0, c: 0, prev:false}, w IN COLLECT(isWin) |
CASE WHEN w
THEN {
c: CASE WHEN s.prev THEN s.c+1 ELSE 1 END,
max: CASE WHEN s.max <= s.c
THEN CASE WHEN s.prev
THEN s.c+1
ELSE CASE WHEN s.max = 0 THEN 1 ELSE s.max END END
ELSE s.max END,
prev: w}
ELSE {c: 0, max: s.max, prev: w} END).max AS maxConsecutiveWins
order by maxConsecutiveWins DESC
limit 1
The case part of the code i understand but i cant seem to figure out why some wins aren't being checked against it.
initially i thought it was an issue with it only counting the away_team matches but it isn't.
Please help. thanks
neo4j cypher
This question is a follow up to the answer given here Finding the most consecutive wins in a rugby league
by @cybersam
My program is for an EPL match.
but my database structure is exactly the same
my problem is this doesn't give the required output.
i tried this on my database and it gives the output as - Manchester united with 14 consecutive wins.
its meant to be 18.
This is the data set
and the tried code
Round,Date,Team 1,FT,HT,Team 2
1,(Fri) 11 Aug 2017 (32),Arsenal FC,4-3,2-2,Leicester City FC
MATCH (t:Team)<-[r]-(g:Match)-[r2]->(t2)
WITH t, r.Ftaway_goal > r2.Fthome_goal AS isWin ORDER BY g.Date, g.Round
RETURN t, REDUCE(s = {max: 0, c: 0, prev:false}, w IN COLLECT(isWin) |
CASE WHEN w
THEN {
c: CASE WHEN s.prev THEN s.c+1 ELSE 1 END,
max: CASE WHEN s.max <= s.c
THEN CASE WHEN s.prev
THEN s.c+1
ELSE CASE WHEN s.max = 0 THEN 1 ELSE s.max END END
ELSE s.max END,
prev: w}
ELSE {c: 0, max: s.max, prev: w} END).max AS maxConsecutiveWins
order by maxConsecutiveWins DESC
limit 1
The case part of the code i understand but i cant seem to figure out why some wins aren't being checked against it.
initially i thought it was an issue with it only counting the away_team matches but it isn't.
Please help. thanks
neo4j cypher
neo4j cypher
edited Jan 25 at 21:43
SP123
asked Jan 4 at 18:38
SP123SP123
33
33
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your data structure is not identical to the one in the original question.
The Ftaway_goal
and Fthome_goal
properties have different names. Therefore, your query's r.Ftaway_goal > r2.Fthome_goal
test is only considering away games as possible wins.
If you used a consistent property name, like goal
, for both home and away games, then a r.goal > r2.goal
test would take both types of games into consideration.
yes its not identical, but the structure of my database is modeled after that just with different names and dataset. i already have nine other queries running on this structure, is there a way to work around this please. i tried doing WITH t, (r.Ftaway_goal > r2.Fthome_goal OR r.Fthome_goal > r2.Ftaway_goal ) AS isWin ORDER BY g.Date, g.Round but this just ends up giving the total number of wins not consecutive wins
– SP123
Jan 5 at 1:33
also the total number of consecutive wins for Manchester City away games alone isn't 14, its less than that. which is why i'm more confused. i cant understand why the output is 14. if i remove the limit the answers for other teams are also just as wrong. i cant tell the logic behind why the code gives the output it does
– SP123
Jan 5 at 1:46
If you don't want to change your property names (which may not be difficult, depending on your other queries), one workaround is to just add an additionalgoal
property to yourTeam
nodes.
– cybersam
Jan 7 at 20:36
ah yes i realized the fundamental difference, been able to correct the structure. works great now. thank you
– SP123
Jan 10 at 17:23
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54044370%2fhow-to-display-the-team-with-the-most-consecutive-win-in-an-epl-match-neo4j%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your data structure is not identical to the one in the original question.
The Ftaway_goal
and Fthome_goal
properties have different names. Therefore, your query's r.Ftaway_goal > r2.Fthome_goal
test is only considering away games as possible wins.
If you used a consistent property name, like goal
, for both home and away games, then a r.goal > r2.goal
test would take both types of games into consideration.
yes its not identical, but the structure of my database is modeled after that just with different names and dataset. i already have nine other queries running on this structure, is there a way to work around this please. i tried doing WITH t, (r.Ftaway_goal > r2.Fthome_goal OR r.Fthome_goal > r2.Ftaway_goal ) AS isWin ORDER BY g.Date, g.Round but this just ends up giving the total number of wins not consecutive wins
– SP123
Jan 5 at 1:33
also the total number of consecutive wins for Manchester City away games alone isn't 14, its less than that. which is why i'm more confused. i cant understand why the output is 14. if i remove the limit the answers for other teams are also just as wrong. i cant tell the logic behind why the code gives the output it does
– SP123
Jan 5 at 1:46
If you don't want to change your property names (which may not be difficult, depending on your other queries), one workaround is to just add an additionalgoal
property to yourTeam
nodes.
– cybersam
Jan 7 at 20:36
ah yes i realized the fundamental difference, been able to correct the structure. works great now. thank you
– SP123
Jan 10 at 17:23
add a comment |
Your data structure is not identical to the one in the original question.
The Ftaway_goal
and Fthome_goal
properties have different names. Therefore, your query's r.Ftaway_goal > r2.Fthome_goal
test is only considering away games as possible wins.
If you used a consistent property name, like goal
, for both home and away games, then a r.goal > r2.goal
test would take both types of games into consideration.
yes its not identical, but the structure of my database is modeled after that just with different names and dataset. i already have nine other queries running on this structure, is there a way to work around this please. i tried doing WITH t, (r.Ftaway_goal > r2.Fthome_goal OR r.Fthome_goal > r2.Ftaway_goal ) AS isWin ORDER BY g.Date, g.Round but this just ends up giving the total number of wins not consecutive wins
– SP123
Jan 5 at 1:33
also the total number of consecutive wins for Manchester City away games alone isn't 14, its less than that. which is why i'm more confused. i cant understand why the output is 14. if i remove the limit the answers for other teams are also just as wrong. i cant tell the logic behind why the code gives the output it does
– SP123
Jan 5 at 1:46
If you don't want to change your property names (which may not be difficult, depending on your other queries), one workaround is to just add an additionalgoal
property to yourTeam
nodes.
– cybersam
Jan 7 at 20:36
ah yes i realized the fundamental difference, been able to correct the structure. works great now. thank you
– SP123
Jan 10 at 17:23
add a comment |
Your data structure is not identical to the one in the original question.
The Ftaway_goal
and Fthome_goal
properties have different names. Therefore, your query's r.Ftaway_goal > r2.Fthome_goal
test is only considering away games as possible wins.
If you used a consistent property name, like goal
, for both home and away games, then a r.goal > r2.goal
test would take both types of games into consideration.
Your data structure is not identical to the one in the original question.
The Ftaway_goal
and Fthome_goal
properties have different names. Therefore, your query's r.Ftaway_goal > r2.Fthome_goal
test is only considering away games as possible wins.
If you used a consistent property name, like goal
, for both home and away games, then a r.goal > r2.goal
test would take both types of games into consideration.
edited Jan 4 at 21:04
answered Jan 4 at 19:57
cybersamcybersam
41.3k53354
41.3k53354
yes its not identical, but the structure of my database is modeled after that just with different names and dataset. i already have nine other queries running on this structure, is there a way to work around this please. i tried doing WITH t, (r.Ftaway_goal > r2.Fthome_goal OR r.Fthome_goal > r2.Ftaway_goal ) AS isWin ORDER BY g.Date, g.Round but this just ends up giving the total number of wins not consecutive wins
– SP123
Jan 5 at 1:33
also the total number of consecutive wins for Manchester City away games alone isn't 14, its less than that. which is why i'm more confused. i cant understand why the output is 14. if i remove the limit the answers for other teams are also just as wrong. i cant tell the logic behind why the code gives the output it does
– SP123
Jan 5 at 1:46
If you don't want to change your property names (which may not be difficult, depending on your other queries), one workaround is to just add an additionalgoal
property to yourTeam
nodes.
– cybersam
Jan 7 at 20:36
ah yes i realized the fundamental difference, been able to correct the structure. works great now. thank you
– SP123
Jan 10 at 17:23
add a comment |
yes its not identical, but the structure of my database is modeled after that just with different names and dataset. i already have nine other queries running on this structure, is there a way to work around this please. i tried doing WITH t, (r.Ftaway_goal > r2.Fthome_goal OR r.Fthome_goal > r2.Ftaway_goal ) AS isWin ORDER BY g.Date, g.Round but this just ends up giving the total number of wins not consecutive wins
– SP123
Jan 5 at 1:33
also the total number of consecutive wins for Manchester City away games alone isn't 14, its less than that. which is why i'm more confused. i cant understand why the output is 14. if i remove the limit the answers for other teams are also just as wrong. i cant tell the logic behind why the code gives the output it does
– SP123
Jan 5 at 1:46
If you don't want to change your property names (which may not be difficult, depending on your other queries), one workaround is to just add an additionalgoal
property to yourTeam
nodes.
– cybersam
Jan 7 at 20:36
ah yes i realized the fundamental difference, been able to correct the structure. works great now. thank you
– SP123
Jan 10 at 17:23
yes its not identical, but the structure of my database is modeled after that just with different names and dataset. i already have nine other queries running on this structure, is there a way to work around this please. i tried doing WITH t, (r.Ftaway_goal > r2.Fthome_goal OR r.Fthome_goal > r2.Ftaway_goal ) AS isWin ORDER BY g.Date, g.Round but this just ends up giving the total number of wins not consecutive wins
– SP123
Jan 5 at 1:33
yes its not identical, but the structure of my database is modeled after that just with different names and dataset. i already have nine other queries running on this structure, is there a way to work around this please. i tried doing WITH t, (r.Ftaway_goal > r2.Fthome_goal OR r.Fthome_goal > r2.Ftaway_goal ) AS isWin ORDER BY g.Date, g.Round but this just ends up giving the total number of wins not consecutive wins
– SP123
Jan 5 at 1:33
also the total number of consecutive wins for Manchester City away games alone isn't 14, its less than that. which is why i'm more confused. i cant understand why the output is 14. if i remove the limit the answers for other teams are also just as wrong. i cant tell the logic behind why the code gives the output it does
– SP123
Jan 5 at 1:46
also the total number of consecutive wins for Manchester City away games alone isn't 14, its less than that. which is why i'm more confused. i cant understand why the output is 14. if i remove the limit the answers for other teams are also just as wrong. i cant tell the logic behind why the code gives the output it does
– SP123
Jan 5 at 1:46
If you don't want to change your property names (which may not be difficult, depending on your other queries), one workaround is to just add an additional
goal
property to your Team
nodes.– cybersam
Jan 7 at 20:36
If you don't want to change your property names (which may not be difficult, depending on your other queries), one workaround is to just add an additional
goal
property to your Team
nodes.– cybersam
Jan 7 at 20:36
ah yes i realized the fundamental difference, been able to correct the structure. works great now. thank you
– SP123
Jan 10 at 17:23
ah yes i realized the fundamental difference, been able to correct the structure. works great now. thank you
– SP123
Jan 10 at 17:23
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54044370%2fhow-to-display-the-team-with-the-most-consecutive-win-in-an-epl-match-neo4j%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown