MieuxVoter / mv-api-spec

Specifications for OpenAPI
MIT License
4 stars 2 forks source link

The /merit-profile endpoint #10

Open roipoussiere opened 4 years ago

roipoussiere commented 4 years ago

Currently, the merit profile is displayed in the result page as an html table.

I suggest an other behavior to facilitate the mv-api integration with other services: adding a dedicated /merit-profile endpoint on the api, that returns the merit profile as an image.

In this way, any service could get and display the image of the merit profile by a simple url call.

I'm currently working on a Python module that generates a such image, that can be used when finished in the mv-api or any Python-related project, which will be callable and via the CLI.

Note that this module (and so the /merit-profile endpoint) does not process MJ data, it only render the results.

Verb used

GET

Parameters

results

Results for each proposal. Results length for each candidate must be equals to mentions length and result sum of each candidate must be equals between them.

width

The image width.

legend

Define how to include the legend that displays the mentions.

labels

Define how to include the labels that displays the proposals / candidates. top / bottom use references (like in the current merit profile), left / right include them directly beside the graph in a sidebar.

sidebar_width

Define the width of the sidebar, in percents of the image width. If there is no enough place to fully display a label, the label will be stripped. Has no effect if labels is set to no, top or bottom.

mentions

The list of mentions that will be used in labels (also used to define the number of mentions).

hints

Define how values are displayed inside merit profile mentions.

median

Define how the median line must be displayed.

extention

Define the extension of the merit profile image. Svg is useful when sharing on websites of forums, png is useful for OpenGraph integration.

guhur commented 4 years ago

Could you define the use-case for using this endpoint? I am not really sure I understand.

For example, I think that if you want to get a graph representation, you would generally want to rank the candidates on the graph according to MJ sorting.

In this case, I think the following procedure is simpler:

  1. Create a poll with POST /polls,
  2. Inject your results inside POST /polls/{poll-id}/judgments.
  3. Ask for the figure: GET /polls/{poll-id}/figure.

Such workflow avoids :

roipoussiere commented 4 years ago

Could you define the use-case for using this endpoint?

For example, I think that if you want to get a graph representation, you would generally want to rank the candidates on the graph according to MJ sorting.

Nether though about this but it's a nice idea.

Ask for the figure: GET /polls/{poll-id}/figure.

Good point, this is indeed simpler and all workflows to avoids you described make sense.

But one thing to be aware is that if you share results images and then delete the poll, all those images will become broken links. A poll-agnostic endpoint can prevent this.

guhur commented 4 years ago

But one thing to be aware is that if you share results images and then delete the poll, all those images will become broken links. A poll-agnostic endpoint can prevent this.

That's why we need to clarify your use-case. In my opinion, if I want to delete a poll (e.g. I discover that someone cheated), I want to make sure that every chart of the results explains that this poll has been invalidated.

all those images will become broken links

Not necessarily. We can delete all the information about the poll itself, but keep the poll id in the database and toggle a "deleted-poll" boolean. This would allow us to display "this poll has been deleted by its organizer".