Skip to content

Commit

Permalink
updated package schema and added start based search
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaSTL committed Nov 15, 2023
1 parent aed48a1 commit fba794a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/Command/Command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,21 @@ namespace Command {
typedef struct Package_s {
std::string name;
std::string git;
std::string git_short;
std::string git_prefixed;
std::vector<std::string> versions;
std::string target_link;
std::string description;
std::string selected_version;
std::string git_description;
std::string language;
std::string license;
std::string owner;
std::string owner_type;
int stars;
int forks;
int open_issues;
int watchers;
int score;
json toJson();
void fromJson(json j);
Expand Down
1 change: 0 additions & 1 deletion src/Command/CommandGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Command {
std::fstream file;
std::string file_name = "config.json";
try {
std::cout << "Project path: " << pro->project_path << std::endl;
file.open((pro->project_path / file_name).string());
json data = json::parse(file);
pro->fromJson(data);
Expand Down
6 changes: 5 additions & 1 deletion src/Command/CommandUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ namespace Command {
using nlohmann::json;

bool Interface::update() {
if (this->args->operator[]("subcommand").as<std::string>() == "packages") {
if(this->args->count("subcommand") == 0){
std::cout << "Usage: update (index)" << ENDL;
return true;
}
if (this->args->operator[]("subcommand").as<std::string>() == "index") {
std::cout << "Updating packages" << ENDL;
updateIndex();
}
Expand Down
25 changes: 25 additions & 0 deletions src/Command/Package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ namespace Command {
data["description"] = this->description;
data["target_link"] = this->target_link;
data["git"] = this->git;
data["git_short"] = this->git_short;
data["git_prefixed"] = this->git_prefixed;
data["selected_version"] = this->selected_version;
data["git_description"] = this->git_description;
data["language"] = this->language;
data["license"] = this->license;
data["owner"] = this->owner;
data["owner_type"] = this->owner_type;
data["stars"] = this->stars;
data["forks"] = this->forks;
data["open_issues"] = this->open_issues;
data["watchers"] = this->watchers;
return data;
}

Expand All @@ -31,7 +43,20 @@ namespace Command {
this->target_link = data["target_link"];
}


this->git = data["git"];
this->git_short = data["git_short"];
this->git_prefixed = data["git_prefixed"];
this->git_description = data["git_description"];
this->language = data["language"];
this->license = data["license"];
this->owner = data["owner"];
this->owner_type = data["owner_type"];
this->stars = data["stars"].get<int>();
this->forks = data["forks"].get<int>();
this->open_issues = data["open_issues"].get<int>();
this->watchers = data["watchers"].get<int>();

}

} // namespace Command
7 changes: 6 additions & 1 deletion src/Command/SearchPackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace Command {
void getPackageScore(Package &package, std::string &query){
int score = 0;
score += getStringScore(package.name, query) * 10;
score += package.stars / 100;
score += getStringScore(package.description, query);
score += getStringScore(package.target_link, query);
package.score = score;
Expand Down Expand Up @@ -112,11 +113,15 @@ namespace Command {
results.begin(), results.end(), 0, [](int a, Package b){
return a + b.score;
});

int averageScore = totalScore / results.size();



auto filterResults = results | std::views::filter([&averageScore](Package package){return package.score > 2 * averageScore;});
auto filterResults = results | std::views::filter(
[&averageScore](Package package){
return package.score > 2 * averageScore;
});
return std::vector<Package>(filterResults.begin(), filterResults.end());
}

Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#endif
int main(int argc, char **argv) {


// LUCAS MAKE SURE YOU INITIALIZE YOUR FUCKING STRUCT YOU TWAT
//std::shared_ptr<Command::Context> ctx = std::make_shared<Command::Context>();
#ifdef TEST
Expand Down

0 comments on commit fba794a

Please sign in to comment.