Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

82 end client is able to get information about members participation statistics #137

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions DSL/Ruuter.public/riigikogu/five-most-recent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
declaration:
call: declare
version: 0.1
name: " most recent voting results service"
description: "Provides information for 5 most-recent voting results"
method: get
returns: json
namespace: common-services

prepareVariables:
assign:
offSet: 5 # to get start date withe enough data
end: ${new Date().toISOString().split('T')[0]}
start: ${new Date(new Date(end).setDate(new Date(end).getDate() - offSet)).toISOString().split('T')[0]}
next: makeAPIRequest

makeAPIRequest:
call: http.get
args:
url: "https://api.riigikogu.ee/api/votings?endDate=${end}&lang=ET&startDate=${start}"
headers:
Accept: "application/json"
result: votingData
error: requestError
next: logStep

logStep:
log: ${votingData.response.body.slice(0, 10)}
next: votingDataFormatting

votingDataFormatting:
assign:
recentVotings: ${votingData.response.body.slice(0, 10)}
votingDetails: ${recentVotings.flatMap(session => session.votings)
.filter(voting => voting.type.value === "Avalik" && voting.relatedDraft)
.sort((voting1, voting2) => new Date(voting2.startDateTime) - new Date(voting1.startDateTime)).slice(0, 5)} # Take the first 5 items
error: dataFormattingError
next: returnResults

returnResults:
return: ${"Viimased viis Riigikogu hääletust- " +
votingDetails[0].relatedDraft.title +
". Kohal-" + votingDetails[0].present +
". Puudus-" + votingDetails[0].absent +
". Poolt-" + votingDetails[0].inFavor +
". Vastu-" + votingDetails[0].against +
". Erapooletu-" + votingDetails[0].neutral +
". Erapooletuks jäi-" + votingDetails[0].abstained +
". " + votingDetails[1].relatedDraft.title +
". Kohal-" + votingDetails[1].present +
". Puudus-" + votingDetails[1].absent +
". Poolt-" + votingDetails[1].inFavor +
". Vastu-" + votingDetails[1].against +
". Erapooletu-" + votingDetails[1].neutral +
". Erapooletuks jäi-" + votingDetails[1].abstained +
". " + votingDetails[2].relatedDraft.title +
". Kohal-" + votingDetails[2].present +
". Puudus-" + votingDetails[2].absent +
". Poolt-" + votingDetails[2].inFavor +
". Vastu-" + votingDetails[2].against +
". Erapooletu-" + votingDetails[2].neutral +
". Erapooletuks jäi-" + votingDetails[2].abstained +
". " + votingDetails[3].relatedDraft.title +
". Kohal-" + votingDetails[3].present +
". Puudus-" + votingDetails[3].absent +
". Poolt-" + votingDetails[3].inFavor +
". Vastu-" + votingDetails[3].against +
". Erapooletu-" + votingDetails[3].neutral +
". Erapooletuks jäi-" + votingDetails[3].abstained +
". " + votingDetails[4].relatedDraft.title +
". Kohal-" + votingDetails[4].present +
". Puudus-" + votingDetails[4].absent +
". Poolt-" + votingDetails[4].inFavor +
". Vastu-" + votingDetails[4].against +
". Erapooletu-" + votingDetails[4].neutral +
". Erapooletuks jäi-" + votingDetails[4].abstained}
next: end

requestError:
return: "Request Error: failed to get last 5 votings data."
next: end

dataFormattingError:
return: "Error: failed to format voting data"
next: end

assignResultsError:
return: "Error: failed to assign results"
next: end

# assignResults: # will not be needed propbably.
# assign:
# sessions:
# - title: ${votingDetails[0].relatedDraft.title}
# present: ${votingDetails[0].present}
# absent: ${votingDetails[0].absent}
# inFavor: ${votingDetails[0].inFavor}
# against: ${votingDetails[0].against}
# neutral: ${votingDetails[0].neutral}
# abstained: ${votingDetails[0].abstained}
# - title: ${votingDetails[1].relatedDraft.title}
# present: ${votingDetails[1].present}
# absent: ${votingDetails[1].absent}
# inFavor: ${votingDetails[1].inFavor}
# against: ${votingDetails[1].against}
# neutral: ${votingDetails[1].neutral}
# abstained: ${votingDetails[1].abstained}
# - title: ${votingDetails[2].relatedDraft.title}
# present: ${votingDetails[2].present}
# absent: ${votingDetails[2].absent}
# inFavor: ${votingDetails[2].inFavor}
# against: ${votingDetails[2].against}
# neutral: ${votingDetails[2].neutral}
# abstained: ${votingDetails[2].abstained}
# - title: ${votingDetails[3].relatedDraft.title}
# present: ${votingDetails[3].present}
# absent: ${votingDetails[3].absent}
# inFavor: ${votingDetails[3].inFavor}
# against: ${votingDetails[3].against}
# neutral: ${votingDetails[3].neutral}
# abstained: ${votingDetails[3].abstained}
# - title: ${votingDetails[4].relatedDraft.title}
# present: ${votingDetails[4].present}
# absent: ${votingDetails[4].absent}
# inFavor: ${votingDetails[4].inFavor}
# against: ${votingDetails[4].against}
# neutral: ${votingDetails[4].neutral}
# abstained: ${votingDetails[4].abstained}
# error: assignResultsError
# next: returnResults
61 changes: 61 additions & 0 deletions DSL/Ruuter.public/riigikogu/members-participation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
declaration:
call: declare
version: 0.1
name: Member Participation Statistics Service
description: A service that provides participation statistics for Riigikogu members.
method: get
returns: json
namespace: common-services

prepareVariables:
assign:
currentDate: ${new Date().toISOString().split('T')[0]} # yyyy-mm-dd
endDate: ${ incoming.params.endDate || currentDate}
startDate: ${ incoming.params.startDate || new Date(new Date(endDate).setMonth(new Date(endDate).getMonth() - 1)).toISOString().split('T')[0] } # yyyy-mm-dd
lang: "ET"
memberName: ${incoming.params.memberName}
next: checkMember

checkMember:
switch:
- condition: ${!memberName}
next: memberNotFound
next: makeAPIRequest

makeAPIRequest:
call: http.get
args:
url: "https://api.riigikogu.ee/api/statistics/participations/plenary?endDate=${endDate}&startDate=${startDate}&lang=${lang}"
headers:
accept: "application/json"
result: kohaloluData
error: returnError
next: filterMember

filterMember:
assign:
memberData: ${kohaloluData.response.body.find(member => member.fullName === memberName)}
next: checkMemberExists

checkMemberExists:
switch:
- condition: ${memberData !== undefined && memberData !== null}
next: returnResult
next: memberNotFound

assigReturnVariables:
assign:

next: returnResult

returnResult:
return: ${memberData.fullName + " on olnud perioodil " + startDate + " - " + endDate + " kohal " + memberData.participated + " korda ja puudunud " + memberData.absent + " korda."}
next: end

memberNotFound:
return: "Error: Member not found."
next: end

returnError:
return: "Error: failed to get participation data."
next: end
Loading