12 Commits

Author SHA1 Message Date
Athul Cyriac Ajay
aaff45b1d4 Merge pull request #30 from ouuan/accurate-graph
feat: more accurate graph
2020-08-16 15:50:54 +05:30
Athul Cyriac Ajay
b37bede506 Merge pull request #29 from RyuaNerin/for-text-centering
Insert space at the end of each line for text centering
2020-08-16 15:32:15 +05:30
Yufan You
215367a2ad refactor: remove duplicate codes in the tests 2020-08-16 16:08:06 +08:00
Yufan You
d827cb172d feat: more accurate graph 2020-08-16 15:57:38 +08:00
RyuaNerin
73c1050f48 Insert space at the end of each line for text centering 2020-08-16 16:39:45 +09:00
Athul Cyriac Ajay
d0c740a1a1 Why only the language stats and not other data from the API? 2020-08-03 14:24:55 +05:30
Athul Cyriac Ajay
6f4f9c9933 Create FUNDING.yml 2020-08-03 14:07:33 +05:30
Athul Cyriac Ajay
442c0dae4d Add flag to specify a commit message of user's choice (#25)
* Make commit message configurable
Fixes #24

* Update Readme for Commit_message flag

Make commit message configurable #24
2020-08-02 17:50:23 +05:30
Athul Cyriac Ajay
fa74a6bca2 Add Travis Build Status 2020-07-27 22:07:39 +05:30
Ashraf Ali
55aaf85a2f Added Tests (#23)
* Fixed Spelling mistake

* Added UnitTesting

* Removed pycache

* Updated Readme to include testing info

* Added gititnore

* Added Travis for Testing
2020-07-27 21:49:32 +05:30
Athul Cyriac Ajay
59c5854cd1 Merge pull request #22 from MetLee/master
Fixed a typo
2020-07-23 22:14:26 +05:30
MetLee
21e5b9c804 Fixed a typo 2020-07-24 00:39:34 +08:00
8 changed files with 88 additions and 10 deletions

4
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,4 @@
# These are supported funding model platforms
ko_fi: athulcyriac
custom: https://www.buymeacoffee.com/JeVlc7T

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
#generated when running the tests
__pycache__/

7
.travis.yml Normal file
View File

@@ -0,0 +1,7 @@
language: python
python:
- "3.7"
install:
- pip install -r requirements.txt
script:
- python -m unittest discover

View File

@@ -1,4 +1,4 @@
# Dev Metrics in Readme
# Dev Metrics in Readme [![Build Status](https://travis-ci.com/athul/waka-readme.svg?branch=master)](https://travis-ci.com/athul/waka-readme)
![Project Preview](https://user-images.githubusercontent.com/8397274/87243943-e6b45c00-c457-11ea-94c9-2aa0bf241be8.png)
@@ -56,7 +56,7 @@ Please follow the steps below:
name: Waka Readme
on:
workflow_dispatch
workflow_dispatch:
schedule:
# Runs at 12am UTC
- cron: '0 0 * * *'
@@ -111,6 +111,17 @@ jobs:
USERNAME: <username> # optional, it will automatically use the username of the owner of the repository who's executing the workflow.
```
## Tests
### Running Tests
To run tests simply execute the following in the directory containing main.py:
```python
python -m unittest discover
```
### Contributing Tests
These tests uses the python Unit testing framework, [unittest](https://docs.python.org/3/library/unittest.html)
Since this project is contained all within one file, 'main.py'. You can simply add a function to the TestMain class in tests/test_main.py, similar to the test_graph function.
## Extras
1. If you want to add the week in the Header of your stats, you can add `HEAD_FLAG: true` in your workflow file like this
@@ -134,3 +145,19 @@ Markdown 52 mins █░░░░░░░░░░░░░░░
Docker 16 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 02.32 %
YAML 7 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 01.07 %
```
2. You can specify a commit message to overrdie the default _"Updated the Graph with new Metrics"_. Here is how you do it
```yml
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
USERNAME: <username>
COMMIT_MESSAGE: Updated the Readme
```
If no commit message is specified in the `yml` file, it defaults to _"Updated the Graph with new Metrics"_
## Why only the language stats and not other data from the API?
I am a fan of minimal designs and the profile readme is a great way to show off your skills and interests. The WakaTime API, gets us a **lot of data** about a person's **coding activity including the editors and Operating Systems you used and the projects you worked on**. Some of these projects maybe secretive and should not be shown out to the public. Using up more data via the Wakatime API will clutter the profile readme and hinder your chances on displaying what you provide **value to the community** like the pinned Repositories. I believe that **Coding Stats is nerdiest of all** since you can tell the community that you are *__exercising these languages or learning a new language__*, this will also show that you spend some amount of time to learn and exercise your development skills. That's what matters in the end :heart:

View File

@@ -21,6 +21,11 @@ inputs:
description: "Displays the week number and days in Readme as title"
default: false
required: false
COMMIT_MESSAGE:
description: "Add a commit message of your choice"
default: "Updated the Graph with new Metrics"
required: false
runs:

20
main.py
View File

@@ -18,6 +18,7 @@ user = os.getenv('INPUT_USERNAME')
waka_key = os.getenv('INPUT_WAKATIME_API_KEY')
ghtoken = os.getenv('INPUT_GH_TOKEN')
show_title = os.getenv("INPUT_SHOW_TITLE")
commit_message = os.getenv("INPUT_COMMIT_MESSAGE")
def this_week() -> str:
@@ -30,10 +31,13 @@ def this_week() -> str:
def make_graph(percent: float) -> str:
'''Make progress graph from API graph'''
done_block = ''
empty_block = ''
pc_rnd = round(percent)
return f"{done_block*int(pc_rnd/4)}{empty_block*int(25-int(pc_rnd/4))}"
blocks = "░▒▓█"
graph = blocks[3] * int(percent / 4 + 1 / 6)
remainder_block = int((percent + 2 / 3) % 4 * 3 / 4)
if remainder_block > 0:
graph += blocks[remainder_block]
graph += blocks[0] * (25 - len(graph))
return graph
def get_stats() -> str:
@@ -58,9 +62,9 @@ def get_stats() -> str:
# following line provides a neat finish
fmt_percent = format(lang['percent'], '0.2f').zfill(5)
data_list.append(
f"{lang['name']}{' '*(pad + 3 - lth)}{lang['text']}{' '*(16 - ln_text)}{make_graph(lang['percent'])} {fmt_percent} %")
f"{lang['name']}{' '*(pad + 3 - lth)}{lang['text']}{' '*(16 - ln_text)}{make_graph(lang['percent'])} {fmt_percent} % ")
print("Graph Generated")
data = ' \n'.join(data_list)
data = '\n'.join(data_list)
if show_title == 'true':
print("Stats with Weeks in Title Generated")
return '```text\n'+this_week()+'\n\n'+data+'\n```'
@@ -70,7 +74,7 @@ def get_stats() -> str:
def decode_readme(data: str) -> str:
'''Decode the contets of old readme'''
'''Decode the contents of old readme'''
decoded_bytes = base64.b64decode(data)
return str(decoded_bytes, 'utf-8')
@@ -93,5 +97,5 @@ if __name__ == '__main__':
rdmd = decode_readme(contents.content)
new_readme = generate_new_readme(stats=waka_stats, readme=rdmd)
if new_readme != rdmd:
repo.update_file(path=contents.path, message='Updated with Dev Metrics',
repo.update_file(path=contents.path, message=commit_message,
content=new_readme, sha=contents.sha, branch='master')

0
tests/__init__.py Normal file
View File

29
tests/test_main.py Normal file
View File

@@ -0,0 +1,29 @@
'''
Tests for the main.py
'''
from main import make_graph
import unittest
class TestMain(unittest.TestCase):
def test_make_graph(self):
'''Tests the make_graph function'''
def test(percent: float, result: str):
self.assertEqual(make_graph(percent), result, f"{percent}% should return {result}")
test(0, "░░░░░░░░░░░░░░░░░░░░░░░░░")
test(100, "█████████████████████████")
test(50, "████████████▒░░░░░░░░░░░░")
test(50.001, "████████████▓░░░░░░░░░░░░")
test(25, "██████▒░░░░░░░░░░░░░░░░░░")
test(75, "██████████████████▓░░░░░░")
test(3.14, "▓░░░░░░░░░░░░░░░░░░░░░░░░")
test(9.901, "██▒░░░░░░░░░░░░░░░░░░░░░░")
test(87.334, "██████████████████████░░░")
test(87.333, "█████████████████████▓░░░")
test(4.666, "█░░░░░░░░░░░░░░░░░░░░░░░░")
test(4.667, "█▒░░░░░░░░░░░░░░░░░░░░░░░")
if __name__ == '__main__':
unittest.main()