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

Restructured API endpoints for ohsomeNow stats #6021

Merged
merged 12 commits into from
Oct 10, 2023

Conversation

HelNershingThapa
Copy link
Contributor

@HelNershingThapa HelNershingThapa commented Aug 9, 2023

Involves the migration of all MissingMaps API endpoints to utilize the endpoints provided by ohsomeNow stats. The changes encompass four distinct sections: homepage stats, project-level stats, user-level stats, and TM-level stats.

Notably, certain data variables are currently absent, while others are seamlessly integrated:

  • Landing Page and Project Statistics: All requisite values obtained.
  • User Detail:
    • Header: The variable changeset_count is missing, which is essential for displaying the user's progress toward the next mapping level.
    • Elements Mapped: The count for POIs mapped and waterways are missing. An unfamiliar key named object_edits has been identified, but its purpose requires clarification.
    • Edits By Numbers: The choice between building_count or buildings_added, as well as road_km_added or road_length needs clarification. Values for added POIs and waterways are absent.
  • Overall TM Stats (Manage > Stats):
    • Total Features: The variables poi_count_add and waterway_km_add are missing.

Enhanced Timestamp Display

  • User Contributions
    user-detail

  • Manage > Stats > Total Features
    overall-stats

  • Project
    Screenshot from 2023-08-21 13-22-40

The environment configuration no longer retains explicit API endpoint definitions like TM_HOMEPAGE_STATS_API_URL and TM_USER_STATS_API_URL. Instead, a more flexible approach utilizes a new base URL (OHSOME_STATS_BASE_URL) and OHSOME_STATS_TOKEN for token usage (for retrieving user stats) in conjunction with endpoints specified at the component level.

@HelNershingThapa HelNershingThapa linked an issue Aug 9, 2023 that may be closed by this pull request
@Hagellach37
Copy link

Hey @HelNershingThapa ,

this is the new response format for the user stats endpoint. I've added a comment to the result fields to indicate the corresponding name in the old osm-stats API.

Please note that the new response does not contain the fields total_poi_count_add and total_waterway_km_add. These fields need to removed from the HOT Tasking "My Contributions" page.

{
    "result":  {
    	"buildings":84,      # total_building_count_add
    	"roads":0.0,         # total_road_km_add
    	"edits":86,          # there is no corresponding field in the old format 
    	"changesets":2,      # changeset_count
    	"userId":1234        # id
    },
    "attribution":{"url":"https://ohsome.org/copyrights", "text":"© OpenStreetMap contributors"},
    "metadata":{"executionTime":646, "requestUrl":"/hot-tm-user?userId=1234","apiVersion":"0.1"},
    "query":{"timespan":{"startDate":"1970-01-01T00:00:00Z","endDate":"2023-08-15T12:17:58Z"}}
}

For the overall and project level stats the response format looks like this:

{
  "result": {
    "changesets": 10040274,
    "users": 330093,
    "roads": 2638799.285,
    "buildings": 143414629,
    "edits": 238880282,
    "latest": "2023-08-02T10:21:31Z"
  },
  "attribution": {
    "url": "https://ohsome.org/copyrights",
    "text": "© OpenStreetMap contributors"
  },
  "metadata": {
    "executionTime": 1151,
    "requestUrl": "/stats/hotosm-project-%2A",
    "apiVersion": "0.1"
  },
  "query": {
    "timespan": {
      "startDate": "1970-01-01T00:00:00Z",
      "endDate": "2023-08-15T12:20:23Z"
    },
    "hashtag": "hotosm-project-*"
  }
}

example.env Outdated Show resolved Hide resolved
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@ramyaragupathy ramyaragupathy linked an issue Sep 25, 2023 that may be closed by this pull request
@royallsilwallz
Copy link
Contributor

royallsilwallz commented Oct 2, 2023

Hey @HelNershingThapa
I was reviewing the PR and was able to solve the merge conflicts. I just have one question before the merge can happen:

  • I've looked for OHSOME_STATS_TOKEN in the ohsome now stats page. I did not see any token/auth related thing in the their website. Where can we find one?

CC: @konishon @ramyaragupathy @varun2948

@HelNershingThapa
Copy link
Contributor Author

The OHSOME_STATS_TOKEN is used exclusively for the /hot-tm-user API endpoint from ohsomeNow. This specific endpoint might have yet to be directly implemented on their website since it is a TM-specific endpoint. Instead, we had access to it through the API documentation that had been provided, and a token has been issued to us specifically for this purpose. I'll DM you the token in Slack.

Additionally, I'd like to inform you about the following to-do items related to this PR:

  • Update the PR to incorporate changes from the merged @tanstack/react-query PR.
  • Update the tooltip to display the message: "These statistics come from ohsome now stats with a delay of xx minutes. Missing fields will be made available soon!"
  • Ensure that all pages in the application gracefully handle the now unavailable stats endpoint.
  • Revise and update the test cases to reflect the recent code changes.

Involves the migration of all MissingMaps API endpoints to utilize the endpoints provided by ohsomeNow stats. The changes encompass four distinct sections, namely homepage stats, project-level stats, user-level stats, and TM level stats.

Removed the definitions of specific API endpoints, such as `TM_HOMEPAGE_STATS_API_URL` and `TM_USER_STATS_API_URL`, from the environment configuration. A new approach was implemented by introducing a new base URL for ohsomeNow (`OHSOME_STATS_BASE_URL`). This new structure enables the specification of endpoints at a component level, as opposed to being bound to the environment configuration.
- Introduce a new component, `StatsTimestamp`, responsible for displaying timestamps with tooltips. This component accepts a `messageType` prop to determine whether to show a generic or project-specific message. The inconsistent icon usage has been resolved, now consistently using an info icon.
- Reorganized the codebase by removing timestamp implementations from the User Contributions and Project Stats components. Instead, these components now utilize the newly introduced `StatsTimestamp` component for timestamp display.
- Integrated the `StatsTimestamp` component into the Total Features section of the overall statistics page.
@HelNershingThapa HelNershingThapa force-pushed the enhancement/5999-ohsomeNow-stats branch from 0c30aea to a5fa2cb Compare October 3, 2023 15:19
@HelNershingThapa HelNershingThapa marked this pull request as ready for review October 3, 2023 17:36
@github-actions github-actions bot added dependencies Pull requests that update a dependency file javascript labels Oct 10, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 36 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@royallsilwallz
Copy link
Contributor

royallsilwallz commented Oct 10, 2023

Hey @ramyaragupathy,
I've made the final push to this PR. We have tested the feature and it’s good to go.
One thing to note:

  • I can see the CircleCI tests are failing, looks like there is an issue with key authentication with GitHub, may be @yogesh can help with that.

CC: @HelNershingThapa @konishon @varun2948

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file scope: frontend scope: translations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

problem with project statistics Switching stats source
4 participants