-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
82 end client is able to get information about members participation …
…statistics (#137) * started riigikogu docs * added members-participation service and created mock file * updated mock members-participation * added readme * updated readme recent-voting service * added recent-voting service * added service and mock for five-most-recent votings service * added service readme * added five-most-recent service * added members-participation statisics service + mock + readme --------- Co-authored-by: Mati Kljukin <matik@matik-5420.ria.ee>
- Loading branch information
Showing
8 changed files
with
680 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.