Skip to content

Commit

Permalink
Feat: Auto readme update with recent stats
Browse files Browse the repository at this point in the history
  • Loading branch information
vsedov committed Mar 9, 2024
1 parent b1ec50c commit 3ec5745
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 66 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
- name: Run pythonAuto
run: |
poetry run python generate_database.py
poetry run python db_checker.py
- name: Commit database changes
run: |
Expand All @@ -54,6 +55,8 @@ jobs:
if [[ ! -z $(git status -s) ]]; then
git add database.json
git commit -m "chore: update plugins database"
git add README.md
git commit -m "chore: update readme stats"
git add dotfiles.json
git commit -m "chore: update dotfiles database"
fi
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ poetry init -> poetry install -> poetry run python ...
# Key Notes

Remember, Robert's doing his best out here in the wilds of GitHub. Treat him well, and he'll treat you to the finest collection of Neovim treasures the internet has to offer. 🎩🔍


# Database Information

<div style='display:flex;flex-direction:row;justify-content:space-between;'><table><tr><td><h3>Top 10 Plugins by Stars</h3><table border="1"><tr><th>Plugin</th><th>Stars</th></tr><tr><td>telescope.nvim</td><td>13298</td></tr><tr><td>lazy.nvim</td><td>10586</td></tr><tr><td>nvim-lspconfig</td><td>9167</td></tr><tr><td>packer.nvim</td><td>7499</td></tr><tr><td>nvim-cmp</td><td>6787</td></tr><tr><td>mason.nvim</td><td>6422</td></tr><tr><td>nvim-tree.lua</td><td>6290</td></tr><tr><td>neorg</td><td>5473</td></tr><tr><td>harpoon</td><td>5155</td></tr><tr><td>lualine.nvim</td><td>5096</td></tr></table></td><td><h3>Top 10 Plugins by Issues</h3><table border="1"><tr><th>Plugin</th><th>Issues</th></tr><tr><td>telescope.nvim</td><td>312</td></tr><tr><td>packer.nvim</td><td>305</td></tr><tr><td>nvim-cmp</td><td>223</td></tr><tr><td>lualine.nvim</td><td>187</td></tr><tr><td>which-key.nvim</td><td>183</td></tr><tr><td>neo-tree.nvim</td><td>172</td></tr><tr><td>neorg</td><td>153</td></tr><tr><td>mason.nvim</td><td>137</td></tr><tr><td>trouble.nvim</td><td>130</td></tr><tr><td>rust-tools.nvim</td><td>121</td></tr></table></td><td><h3>Top 10 Plugins by Forks</h3><table border="1"><tr><th>Plugin</th><th>Forks</th></tr><tr><td>nvim-lspconfig</td><td>1978</td></tr><tr><td>null-ls.nvim</td><td>802</td></tr><tr><td>telescope.nvim</td><td>748</td></tr><tr><td>nvim-tree.lua</td><td>589</td></tr><tr><td>lualine.nvim</td><td>431</td></tr><tr><td>nvim-cmp</td><td>339</td></tr><tr><td>tokyonight.nvim</td><td>321</td></tr><tr><td>harpoon</td><td>312</td></tr><tr><td>lspsaga.nvim</td><td>273</td></tr><tr><td>ChatGPT.nvim</td><td>264</td></tr></table></td></tr></table></div>

### Final Stats
- Total Plugins: 2425
- Lua Plugins: 2425
- Proportion of Lua Plugins (%): 100.00
- Average Activity Score: 199.43
165 changes: 118 additions & 47 deletions db_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rich.console import Console
from rich.table import Table


class DatabaseAnalyzer:

def __init__(self, database_path='database.json', lengthA=10, lengthB=10):
Expand Down Expand Up @@ -37,8 +38,8 @@ def simplify_language_distribution(self):
# Use get to safely access the count for each language, defaulting to 0 if not found
# This approach avoids KeyError for languages not present in language_counts
self.plugins_df['simplified_language'] = self.plugins_df[
'language'].apply(
lambda x: x if language_counts.get(x, 0) > 1 else 'Other')
'language'].apply(lambda x: x
if language_counts.get(x, 0) > 1 else 'Other')

def calculate_statistics(self):
stats_df = self.plugins_df[[
Expand All @@ -61,26 +62,27 @@ def get_topics_distribution(self):
return topics_series.head(self.lengthB) # Only the top 5 topics

def print_summary(self):
self.console.print(
f"Total plugins: {len(self.plugins_df)}", style="bold green")

stats_df = self.calculate_statistics()
self.console.print("\nStatistical Summary:", style="bold underline")
self.print_table(stats_df, ['Metric', 'Mean', 'Standard Deviation'])

lang_dist = self.get_language_distribution()
self.console.print("\nLanguage distribution:", style="bold underline")
self.print_table(lang_dist, ['Language', 'Count'])

avg_activity_score_by_lang = self.get_average_activity_score_by_language(
)
self.console.print(
"\nAverage Activity Score by Language:", style="bold underline")
self.print_table(
avg_activity_score_by_lang, ['Language', 'Average Activity Score'])
# self.console.print(
# f"Total plugins: {len(self.plugins_df)}", style="bold green")
#
# stats_df = self.calculate_statistics()
# self.console.print("\nStatistical Summary:", style="bold underline")
# self.print_table(stats_df, ['Metric', 'Mean', 'Standard Deviation'])
#
# lang_dist = self.get_language_distribution()
# self.console.print("\nLanguage distribution:", style="bold underline")
# self.print_table(lang_dist, ['Language', 'Count'])

# avg_activity_score_by_lang = self.get_average_activity_score_by_language(
# )
# self.console.print("\nAverage Activity Score by Language:",
# style="bold underline")
# self.print_table(avg_activity_score_by_lang,
# ['Language', 'Average Activity Score'])

topics_distribution = self.get_topics_distribution()
self.console.print("\nTop Topics distribution:", style="bold underline")
self.console.print("\nTop Topics distribution:",
style="bold underline")
self.print_table(topics_distribution, ['Topic', 'Count'])

def print_table(self, data, columns):
Expand All @@ -104,9 +106,8 @@ def print_top_plugins(self):
}

for category, column_name in categories.items():
self.console.print(
f"\nTop {self.lengthA} Plugins by {category}:",
style="bold underline magenta")
self.console.print(f"\nTop {self.lengthA} Plugins by {category}:",
style="bold underline magenta")
top_plugins = self.plugins_df.nlargest(self.lengthA,
column_name)[[column_name]]

Expand All @@ -120,40 +121,110 @@ def print_top_plugins(self):
self.console.print(table)

total_plugins = len(self.plugins_df)
lua_plugins = len(self.plugins_df[self.plugins_df['language'] == 'Lua'])
proportion_lua = (lua_plugins/total_plugins) * 100
lua_plugins = len(
self.plugins_df[self.plugins_df['language'] == 'Lua'])
proportion_lua = (lua_plugins / total_plugins) * 100
average_activity_score = self.plugins_df['activity_score'].mean()

table = Table(show_header=True, header_style="bold magenta")
table.add_column("Total Plugins", style="dim", justify="right")
table.add_column("Lua Plugins", style="dim", justify="right")
table.add_column(
"Proportion of Lua Plugins (%)", style="dim", justify="right")
table.add_column("Average Activity Score", style="dim", justify="right")
table.add_column("Proportion of Lua Plugins (%)",
style="dim",
justify="right")
table.add_column("Average Activity Score",
style="dim",
justify="right")

table.add_row(
str(total_plugins), str(lua_plugins), f"{proportion_lua:.2f}",
f"{average_activity_score:.2f}")
table.add_row(str(total_plugins), str(lua_plugins),
f"{proportion_lua:.2f}", f"{average_activity_score:.2f}")

self.console.print(table)

def generate_markdown_table(self, data, columns):
markdown_table = "| " + " | ".join(columns) + " |\n"
markdown_table += "| " + " | ".join(['---'] * len(columns)) + " |\n"
if isinstance(data, pd.Series):
for index, value in data.items():
markdown_table += "| " + " | ".join([str(index),
str(value)]) + " |\n"
else:
for index, row in data.iterrows():
markdown_table += "| " + index + " | " + f"{row['mean']:.2f}" + " | " + f"{row['std']:.2f}" + " |\n"
return markdown_table

def save_to_markdown(self):
new_content = ""
categories = {
"Stars": "stargazers_count",
"Issues": "open_issues_count",
"Forks": "forks_count"
}

# Generate HTML for the top plugins in each category
plugins_html = self.generate_html_for_plugins(categories)
new_content += "<div style='display:flex;flex-direction:row;justify-content:space-between;'>" + plugins_html + "</div>\n\n"

# Final stats in Markdown
total_plugins = len(self.plugins_df)
lua_plugins = len(
self.plugins_df[self.plugins_df['language'] == 'Lua'])
proportion_lua = (lua_plugins / total_plugins) * 100
average_activity_score = self.plugins_df['activity_score'].mean()
new_content += "### Final Stats\n"
new_content += f"- Total Plugins: {total_plugins}\n"
new_content += f"- Lua Plugins: {lua_plugins}\n"
new_content += f"- Proportion of Lua Plugins (%): {proportion_lua:.2f}\n"
new_content += f"- Average Activity Score: {average_activity_score:.2f}\n"

# Read and split the existing README
try:
with open("README.md", "r+") as md_file:
content = md_file.read()
parts = content.split("# Database Information", 1)
updated_content = parts[
0] + "# Database Information\n\n" + new_content
md_file.seek(0)
md_file.write(updated_content)
md_file.truncate()
except FileNotFoundError:
with open("README.md", "w") as md_file:
md_file.write("# Database Information\n\n" + new_content)

def generate_html_for_plugins(self, categories):
html_content = '<table><tr>'
for category, column_name in categories.items():
top_plugins = self.plugins_df.nlargest(self.lengthA,
column_name)[[column_name]]
html_content += '<td><h3>Top 10 Plugins by ' + category + '</h3>'
html_content += '<table border="1"><tr><th>Plugin</th><th>' + category + '</th></tr>'
for plugin_name, row in top_plugins.iterrows():
html_content += '<tr><td>' + plugin_name + '</td><td>' + str(
row[column_name]) + '</td></tr>'
html_content += '</table></td>'
html_content += '</tr></table>'
return html_content


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Check the database')
parser.add_argument(
'--db',
help='Path to the database file',
default='database.json',
type=str)
parser.add_argument(
"--lenA", help="Length of items you want to view", default=10, type=int)
parser.add_argument(
"--lenB",
help="Length of Topic Distribution you want to view",
default=15,
type=int)
parser.add_argument('--db',
help='Path to the database file',
default='database.json',
type=str)
parser.add_argument("--lenA",
help="Length of items you want to view",
default=10,
type=int)
parser.add_argument("--lenB",
help="Length of Topic Distribution you want to view",
default=10,
type=int)

args = parser.parse_args()
analyzer = DatabaseAnalyzer(
database_path=args.db, lengthA=args.lenA, lengthB=args.lenB)
analyzer.print_summary()
analyzer.print_top_plugins()
analyzer = DatabaseAnalyzer(database_path=args.db,
lengthA=args.lenA,
lengthB=args.lenB)
# analyzer.print_summary()
# analyzer.print_top_plugins()
analyzer.save_to_markdown()
25 changes: 6 additions & 19 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,10 @@ def make_jobs(base) -> None:
def name_function(x, y):
return any(x.lower().startswith(ig.lower()) for ig in y)


fixed_plugin_conds = [
]
fixed_plugin_conds = []
fixed_dotfile_conds = [
fullname_mapper(
lambda x, y: y.lower() in x.lower(),unwanted_config
lambda x, y: y.lower() in x.lower(), unwanted_config
), # checks if any of the unwanted config names are in d['full_name']
description_mapper(
lambda x,
Expand All @@ -541,30 +539,19 @@ def name_function(x, y):
), # check if any of the unwanted config names are in d['description']
]
both_conditions = [
language_mapper(
lambda x, y: x.lower() == "lua", ["lua"]
)
language_mapper(lambda x, y: x.lower() == "lua", ["lua"])
]

optional_plugin_conds = [
ends_nvim,

optional_plugin_conds = [ends_nvim,]
optional_dotfile_conds = [begins_dot,]

]
optional_dotfile_conds = [
begins_dot,
]

conds = (fixed_plugin_conds,fixed_dotfile_conds)
conds = (fixed_plugin_conds, fixed_dotfile_conds)
cases = {
# mappings for conditions based on conditions
(1, 0): "plugin_count",
(0, 1): "dotfile_count",
}




def make_jobtype(response):
plugin_data = response
# case = tuple(min(1, sum(cn(plugin_data) for cn in c)) for c in conds)
Expand Down

0 comments on commit 3ec5745

Please sign in to comment.