Skip to content

Commit

Permalink
Add voting hours to election schema (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
krystof-k authored Sep 3, 2023
1 parent 0088c41 commit 082709e
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 54 deletions.
11 changes: 3 additions & 8 deletions data/instance/volebnakalkulacka.sk/nrsr-2023/election.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
"id": "05c64bc5-aa2e-4457-ab30-336f7cf9131b",
"key": "nrsr-2023"
},
"rounds": [
"votingHours": [
{
"number": 0,
"votingHours": [
{
"start": "2023-09-30T07:00:00+02:00",
"end": "2023-09-30T22:00:00+02:00"
}
]
"start": "2023-09-30T07:00:00+02:00",
"end": "2023-09-30T22:00:00+02:00"
}
]
}
2 changes: 1 addition & 1 deletion data/schemas/candidates-answers.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"$ref": "./answers.schema.json"
}
},
"additionalProperties": false
"unevaluatedProperties": false
}
24 changes: 23 additions & 1 deletion data/schemas/election.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,36 @@
"items": {
"$ref": "./round.schema.json"
}
},
"votingHours": {
"title": "Voting hours",
"description": "One or multiple voting hours for the election",
"type": "array",
"minItems": 1,
"items": {
"$ref": "./time-period.schema.json"
}
}
},
"unevaluatedProperties": false,
"required": [
"id",
"key",
"createdAt",
"title",
"shortTitle",
"calculatorGroup"
]
],
"dependentSchemas": {
"rounds": {
"not": {
"required": ["votingHours"]
}
},
"votingHours": {
"not": {
"required": ["rounds"]
}
}
}
}
39 changes: 1 addition & 38 deletions data/schemas/round.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,7 @@
"type": "array",
"minItems": 1,
"items": {
"title": "Voting period",
"type": "object",
"unevaluatedProperties": false,
"properties": {
"start": {
"title": "Start time",
"description": "Start date (or time) of a voting period in the ISO 8601 format",
"oneOf": [
{
"type": "string",
"format": "date",
"examples": ["2023-01-13"]
},
{
"type": "string",
"format": "date-time",
"examples": ["2023-01-13T14:00:00+01:00"]
}
]
},
"end": {
"title": "End time",
"description": "End date (or time) of a voting period in the ISO 8601 format",
"oneOf": [
{
"type": "string",
"format": "date",
"examples": ["2023-01-13"]
},
{
"type": "string",
"format": "date-time",
"examples": ["2023-01-13T14:00:00+01:00"]
}
]
}
},
"required": ["start", "end"]
"$ref": "./time-period.schema.json"
}
}
},
Expand Down
43 changes: 43 additions & 0 deletions data/schemas/time-period.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://www.volebnikalkulacka.cz/data/schemas/time-period.schema.json",
"title": "Time period",
"description": "Time period from–to",
"type": "object",
"properties": {
"start": {
"title": "Start time",
"description": "Start date (or time) of a voting period in the ISO 8601 format",
"oneOf": [
{
"type": "string",
"format": "date",
"examples": ["2023-01-13"]
},
{
"type": "string",
"format": "date-time",
"examples": ["2023-01-13T14:00:00+01:00"]
}
]
},
"end": {
"title": "End time",
"description": "End date (or time) of a voting period in the ISO 8601 format",
"oneOf": [
{
"type": "string",
"format": "date",
"examples": ["2023-01-13"]
},
{
"type": "string",
"format": "date-time",
"examples": ["2023-01-13T14:00:00+01:00"]
}
]
}
},
"unevaluatedProperties": false,
"required": ["start", "end"]
}
14 changes: 12 additions & 2 deletions data/types/election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export type Number = number;
*
* @minItems 1
*/
export type VotingHours = [VotingPeriod, ...VotingPeriod[]];
export type VotingHours = [TimePeriod, ...TimePeriod[]];
/**
* Start date (or time) of a voting period in the ISO 8601 format
*/
Expand All @@ -79,6 +79,12 @@ export type StartTime = string | string;
* End date (or time) of a voting period in the ISO 8601 format
*/
export type EndTime = string | string;
/**
* One or multiple voting hours for the election
*
* @minItems 1
*/
export type VotingHours1 = [TimePeriod, ...TimePeriod[]];

/**
* Election provides various details about an election such as districts and rounds
Expand All @@ -95,6 +101,7 @@ export interface Election {
calculatorGroup: CalculatorGroup;
districts?: OrderedListOfElectionDistricts;
rounds?: OrderedListOfElectionRounds;
votingHours?: VotingHours1;
[k: string]: unknown;
}
/**
Expand All @@ -121,7 +128,10 @@ export interface Round {
votingHours?: VotingHours;
[k: string]: unknown;
}
export interface VotingPeriod {
/**
* Time period from–to
*/
export interface TimePeriod {
start: StartTime;
end: EndTime;
[k: string]: unknown;
Expand Down
14 changes: 12 additions & 2 deletions data/types/elections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export type Number = number;
*
* @minItems 1
*/
export type VotingHours = [VotingPeriod, ...VotingPeriod[]];
export type VotingHours = [TimePeriod, ...TimePeriod[]];
/**
* Start date (or time) of a voting period in the ISO 8601 format
*/
Expand All @@ -79,6 +79,12 @@ export type StartTime = string | string;
* End date (or time) of a voting period in the ISO 8601 format
*/
export type EndTime = string | string;
/**
* One or multiple voting hours for the election
*
* @minItems 1
*/
export type VotingHours1 = [TimePeriod, ...TimePeriod[]];
/**
* List of elections
*/
Expand All @@ -99,6 +105,7 @@ export interface Election {
calculatorGroup: CalculatorGroup;
districts?: OrderedListOfElectionDistricts;
rounds?: OrderedListOfElectionRounds;
votingHours?: VotingHours1;
[k: string]: unknown;
}
/**
Expand All @@ -125,7 +132,10 @@ export interface Round {
votingHours?: VotingHours;
[k: string]: unknown;
}
export interface VotingPeriod {
/**
* Time period from–to
*/
export interface TimePeriod {
start: StartTime;
end: EndTime;
[k: string]: unknown;
Expand Down
7 changes: 5 additions & 2 deletions data/types/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type Number = number;
*
* @minItems 1
*/
export type VotingHours = [VotingPeriod, ...VotingPeriod[]];
export type VotingHours = [TimePeriod, ...TimePeriod[]];
/**
* Start date (or time) of a voting period in the ISO 8601 format
*/
Expand All @@ -32,7 +32,10 @@ export interface Round {
votingHours?: VotingHours;
[k: string]: unknown;
}
export interface VotingPeriod {
/**
* Time period from–to
*/
export interface TimePeriod {
start: StartTime;
end: EndTime;
[k: string]: unknown;
Expand Down
24 changes: 24 additions & 0 deletions data/types/timePeriod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

/**
* Start date (or time) of a voting period in the ISO 8601 format
*/
export type StartTime = string;
/**
* End date (or time) of a voting period in the ISO 8601 format
*/
export type EndTime = string;

/**
* Time period from–to
*/
export interface TimePeriod {
start: StartTime;
end: EndTime;
[k: string]: unknown;
}

1 comment on commit 082709e

@vercel
Copy link

@vercel vercel bot commented on 082709e Sep 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.