Code Monkey home page Code Monkey logo

coh3-stats's Introduction

COH3 Stats

GitHub release (latest by date) DeepScan grade Uptime Robot ratio (30 days) Discord

Website https://coh3stats.com/

We are looking not only for developers but anyone who would like to contribute in building the best site with most info for Company of Heroes 3. All the data will be open source for anyone to use! We need people to get the data from the game / organize the data. Come up with layouts and much more.

Anyone can put a hand in building this site. Please consider joining our Discord.

We have open sourced our underlying data https://coh3stats.com/other/open-data

  • Leaderboards, Matches << which we scrape and get from Relic API
  • Data (definitions / images ) which << which we get from the game files

Getting Started with development

Master branch is deployed to https://dev.coh3stats.com/

First install dependencies:

yarn install

Run the development server:

yarn dev

Open http://localhost:3000 with your browser to see the result. You can start editing the page by modifying pages/index.tsx. The page auto-updates as you edit the file.

Before making an MR please create an issue describing what you want to change and how you want to change it so we can have some discussion. Furthermore, it avoids multiple people working on the same thing.

Feel free to create a fork and make an MR. Before PR you can test your code with yarn build to make sure it builds. Also make sure the prettier is right yarn fix and yarn test

Development conventions:

  • Name the files with - instead of camelCase. Eg color-scheme-toggle.tsx
  • Try not to add any more eslint warnings (Don't worry if you don't know how to solve it though, we can solve on MR)
  • Prettier and eslint should cover the rest (Don't forget to run it)
  • We are using Mantine component library
  • You can find the routing for pages in the folder pages (includes SSR code, data fetching, etc)
  • You can find the implementation of the React code for each page in the folder screens (includes the UI code)
  • You can find the components in the folder components (includes the UI code which is reused across the app)

Development approach

How to:

Add new map image and name

Maps are specified in https://github.com/cohstats/coh3-stats/blob/master/src/coh3/coh3-data.ts#L284

Utilize images from the game

You can use the function getIconsPathOnCDN where you can pass the image name or the full path and it should automatically resolve it on our hosting https://github.com/cohstats/coh3-stats/blob/master/src/utils.ts#L22 If the image is not found there, you can always add it to the /public folder.

How to update the data after a new game patch

  1. Go to https://github.com/cohstats/coh3-data and generate the new data as per readme
  2. Create a new tag in coh3-data as per readme
  3. Update config.ts in the root 4. Add the patch into object patches 5. Update latestPatch variable with the key of the new patch
  4. Run the project and verify that all pages work as expected

How to update the sitemap after adding new pages

You can run the automated workflow in GitHub for this.

Or manually you can do the following:

  1. Run yarn build
  2. Run yarn sitemap
  3. Check changes in public/sitemap.xml
  4. If the pages are not there, you can add them manually in next-sitemap.config.js
  5. Commit the changes

For more info see readme at https://www.npmjs.com/package/next-sitemap

Generating the links to all units:

We have a special script for that.

  1. You need Node 19+
  2. Run
npx --yes ts-node --compiler-options "{\"module\":\"commonjs\"}" scripts/unit-paths.ts > unit-paths.txt

NextJS development

We would like to have most of the pages which require some data SSR ( Server Side Rendered).

https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props.

Example pages:

  • Home Page
  • Player Cards
  • Leaderboards
  • ...
  • Generally any page which loads data from DB or API

The rest of the pages should be SSG (Static Site Generation).

Example pages:

  • Unit Stats
  • ...
  • Generally any page which doesn't load any data from API

Reasons:

  • Because it's a public website, SSR pages will be much better read by search engines and it will provide an overall better experience.
  • All the data fetching (from DB, cloud functions and other) should happen in SSR, so that we can offer site avaliabily everywhere, as GCP services are blocked in some countries ( China, Russia).
  • The SSR functions have the capability to connect to public APIs, retrieve data from Firestore, and invoke cloud functions when necessary.
  • The SSR functions should remain lightweight. For extensive data computations, utilize Cloud Functions on GCP, enabling performance control.
  • The complete source code for our Next.js frontend will be available in this repository and will be open source.
  • The BE of the CF will be closed source because, we will most likely connect to sensitive APIs.

image

High level architecture

image

COH3 Stats technology stack

App platform:

  • Firebase

Frontend:

  • NextJS (React) as main technology used
  • Edgio as a hosting platform
  • Mantine as a component library

Backend:

  • GCP Cloud
  • Firebase Cloud Functions - in TypeScript
  • Database:
    • Firestore - stats, players, matches
    • GCP Storage (leaderboards, matches)

Additional domains

  • cdn.coh3stats.com - Contains all the images | hosted on Firebase hosting
  • storage.coh3stats.com - Contains matches and leaderboards | hosted on GCP Storage
  • cache.coh3stats.com - Cache for API calls
  • data.coh3stats.com - CDN for the data files hosted at Github - coh3-data repo

Learn More about NextJS

To learn more about Next.js, have a look at the following resources:

coh3-stats's People

Contributors

chewya avatar chris-nos avatar github-actions[bot] avatar imgbot[bot] avatar imgbotapp avatar johannesmerkt avatar kingdarboja avatar kingtaytay avatar komnb14 avatar kuv2707 avatar marktallentire avatar mikulasmascautanu avatar petrvecera avatar renovate[bot] avatar rickvanbuuren avatar rysllvn avatar timhbt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

coh3-stats's Issues

Homepage - Create a Reddit card component

Status: Dev Ready

On page https://coh2stats.com/ we have reddit component, which looks like this
image

Taks:

You can edit the source data in here https://github.com/cohstats/coh3-stats/blob/master/src/reddit-api.ts

You can re-use the components and source code from version 2:
It's here https://github.com/cohstats/coh2stats/tree/master/packages/web/src/components/reddit

Overall we would like to replicate this website https://aoe4world.com/ so you can look at it as inspiration.

Add summary of faction to the player card

On the player card we have table summary for each faction. This table is too wide. We can put some data next to it.
It would be great to create a summary card which would show more info about that particular faction.

The task:

  • Make the table smaller
  • Add card next to the table
    The card should have this information:
  • Best ELO xxx in xxx (1v1)
  • Best rank xxx in xxx (2v2 for example)
  • Overall winrate xxx
  • Total games xxxx
  • Last game xxx

image

This should be for all factions.
Try to play with something which will look nice.

Don't forget about the mobile view. There the card should probably jump under the table.

All the source code and info is in this file https://github.com/cohstats/coh3-stats/blob/master/components/player-card/player-standings.tsx

The DPS chart is "flickering" on change

When you change something from the dropdowns on the DPS chart https://coh3stats.com/explorer/dps
You can briefly see the footer to jump down. It's CLS - content layout shift.

I think we need to assign min height to the chart / or the page container.

I wanted to do that, but than I noticed that on the mobile page - it's nicely small, so we might need to add 2 min sizes / mobile and desktop? Something like that.

@chris-nos let me know on Discord if you want look into this

Twitch Stream - freezes when you navigate away and back

When you navigate away from the page and back to it, the twitch streams freezes. Eror in cosnole:
Uncaught TypeError: Cannot read properties of undefined (reading 'setChannel')

Steps:

  1. Go to https://coh3stats.com/
  2. Navigate to https://coh3stats.com/about (click on about button)
  3. Click home

Possible issue:

  • Misalignment between .json hydronation version / loaded version

Possible solution:

  • The twitch container should be only client rendered / the same way we do it for last game timestamp

Add system theme as option for light and dark mode

The option to switch between light/dark modes is great. Many sites such as https://developer.mozilla.org/en-US/ have a third option, which is to check the system theme first. For me personally this is what I would use since I have my OS switch between light and dark based on time of day and find it great.

My understanding is that the light/dark switching is done through the mantine library so not sure how much it would be to get this implemented.

I'm not planning on starting on this right now so if someone else wants to feel free. I'll update later if I start on this though.

Disable prefetching on the links - mainly in the units pages / explorer

When you navigate to page https://dev.coh3stats.com/explorer/races/british/units , open dev tools, network tab. However over the units you will see that it's making tens / hundreds of requests.

It's prefetching from NextJS, we need to disable this. It's pulling GBs of data ... those pages are big ..


Edit: I optimized the pages, we were loading a lot of big data / but anyway I think we could disable prefetch on units as it's still a hundreds of requests

Add unit stats

The source data for this should be JSON, it should be separated by PATH. So you can select a patch version from a drop down.

Create those jsons in /src/coh3/data ...
Create a folder in /pages/units/...

It's up to you how to to code those units

Inspiration for good design can be taken from here https://aoe4world.com/explorer/civs/english/units/trader

recent matches played ago format

If the match was not even an hour ago, it is nicer to display the minutes ago.
1h < time < 10h should display hours without 0 in front.

Timeago.js package is already installed and I changed formatMatchTime (marked as old) function from utils.ts to timeage.js,

grafik

Twitch - disable autoplay on mobile devices

I added autoplay of twitch stream, but it would be wise not to enable it on mobile devices - it would just suck the data from the users.

TODO: Disable autoplay on mobile devices

Mantine witn Nextjs

I am currently working with mantine and nextjs in another project. This is where i had to realize that nextjs SSR with mantine there is a managed starter template https://github.com/mantinedev/mantine-next-template .

Since there is some complex setup needed to make mantine and nextjs work together I would suggest starting with that template.

also really nice in the template is the storybook that is already set up for you. Which is very usefull when designing components

Filter on the table is not visible when there are no data

When you try to filter table and you remove all the data the filter is hidden.

image

image

We need to get the poover over the table somehow. I tried to play with the z-index but it didn't help on the popover. Maybe we need to apply it somewhere else?

Filters and sorting recent matches tab

There are only 10 matches per match type, but it still might be nice to be able to filter the recent matches tab (by game sized, faction, win/lose, etc.). What do you think? I was thinking filtering <Select />. Also could make the column headers clickable for sorting.

I was thinking this might be a good first feature/issue for myself. I've used react plenty, but would be getting used to mantine and next. I don't think there would be much to this that is next specific since all of the data is already fetched for this tab.

Mantine Datatable unique key prop error

Probably not an important fix, but every occurence (leaderboard / playercard) of the mantine datatable currently causes this error:
grafik

Couldn't figure out why but it seems to be inside the render function of the column prop
grafik

this is the only issue I found about this:
icflorescu/mantine-datatable#182
it seems to be our fault

Create a leaderboard small card for index

We need to create a small leaderboard panel on the index page.

It should show 10 players, it will be just 1v1, there will be switch for all 4 factions (we could maybe use just the faction icons).
It should just show columns: rank, elo, alias, streak, ration, total, last game ?? We can test this and see how it looks, maybe we will need to remove some of it out to make it smaller.

If you want to pick this, feel free to ask for additional questions.

We can take inspiration from https://aoe4world.com/

image

Hacktoberfest - implement table for displaying leaderboards

We have leaderboards on site which look like this:
https://coh2stats.com/leaderboards

We need to replicate this table in mantine:

Implement just the table - don't worry about the different inputs (selecting factions and so on ) - we want to have sorting too.
image

You can inspire or get any code in the COH2 project https://github.com/cohstats/coh2stats/blob/master/packages/web/src/pages/ladders/leaderboards.tsx

Ask if you have any questons

Player card - Optimize the SSR function

On the player card - we have 2 views, one is player card, second one is for matches.

For example: https://coh3stats.com/players/871
And: https://coh3stats.com/players/871?view=recentMatches

For rendering just the player info we need - jus player info
For rendering matches, we need player info + recent matches.

There are 2 ways how to approach player recent matches:

  1. User has link, he goes directly https://coh3stats.com/players/871?view=recentMatches , we need to make 2 request
  2. Use is on player profile and than clicks on recentMatches, in this case it would be enough to do just 1 request, to get the data for matches. But we again make 2 requests for both player card and matches.

TASK:
We need to figure out, when you already have player info, don't make the request for player info again.
The code is here https://github.com/cohstats/coh3-stats/blob/master/pages/players/%5BplayerID%5D.tsx#L172

Problem: We have ~25k player card displayed each day, but requests on the BE are ~50k. It's eating $$

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.