Go to file
hirrolot19 776db0f0f3 add README 2024-05-11 16:03:53 +02:00
README.md add README 2024-05-11 16:03:53 +02:00
go.mod add sorting by zscore 2022-08-10 23:09:28 +02:00
go.sum add sorting by zscore 2022-08-10 23:09:28 +02:00
main.go add README 2024-05-11 16:03:53 +02:00
packages.txt trying to remove dependencies 2023-05-10 17:20:12 +02:00
popularities.txt add popularities and trending data 2022-08-11 09:43:17 +02:00
trending-pkgs.go trying to remove dependencies 2023-05-10 17:20:12 +02:00
trending.txt add popularities and trending data 2022-08-11 09:43:17 +02:00

README.md

The script is designed to fetch package popularity data from the https://pkgstats.archlinux.de/api/packages API, calculate different metrics based on the popularity data, and then sort the packages according to the chosen metric. The sorting methods available are:

  1. Total Gain: Sort packages based on the increase in popularity.
  2. Relative Gain: Sort packages based on the percentage increase in popularity.
  3. Logarithmic Gain: Sort packages based on the ratio of the current popularity to the popularity from a while back.
  4. Combined Score: Sort packages based on a score that combines the total gain and relative gain.
  5. Tiered: First, sort packages based on the total gain. For packages with the same total gain, sort them based on their relative gain.

Here's a step-by-step explanation of how you can implement the script yourself:

  1. Define the necessary data structures: Define structs to represent the package popularity data and the API response. For example, you might have a PackagePopularity struct to hold information about a single package, and a PackageData struct to hold the API response.

  2. Fetch package data from the API: Write a function to fetch package data from the https://pkgstats.archlinux.de/api/packages API. This function should make an HTTP GET request to the API endpoint, passing the necessary query parameters (e.g., limit and offset) to fetch the data in batches. The API response should be unmarshaled into the PackageData struct you defined earlier.

  3. Calculate gain metrics: Define functions to calculate the different gain metrics (total gain, relative gain, logarithmic gain, and combined score) based on the package popularity data. These functions should take a PackagePopularity struct as input and return the calculated metric.

  4. Sort packages based on the chosen metric: Write a function to sort the packages based on the chosen metric. This function should take a slice of PackagePopularity structs and the sorting method as input. It should create a slice of PackageWithScore structs (or a similar struct that holds the package name and the corresponding score) and sort this slice based on the chosen metric.

  5. Handle command-line arguments: Use the flag package to handle command-line arguments. This will allow users to specify the sorting method, whether to use cached package data, and the file path for caching/loading package data.

  6. Load or fetch package data: If the user chooses to use cached package data, load the package data from the specified file. Otherwise, fetch the package data from the API using the function you wrote in step 2.

  7. Sort and print the packages: Call the sorting function you wrote in step 4, passing the package data and the chosen sorting method. Then, print the sorted package names to the console.

  8. Implement caching (optional): If desired, you can implement caching functionality to save the fetched package data to a file and load it from the file on subsequent runs.

Throughout the implementation, you'll need to handle errors, parse JSON data, and potentially use third-party libraries (e.g., for handling command-line arguments or making HTTP requests).

Remember, this is a high-level explanation, and you'll need to write the actual code to implement the functionality. If you encounter any specific issues or have questions during the implementation process, feel free to ask for clarification or additional guidance.