Skip to content
This repository was archived by the owner on Aug 20, 2023. It is now read-only.

Commit 0a3344c

Browse files
authored
Merge pull request #82 from cloudnativedaysjp/fix/get_votes_csv_from_weaver
Fix: get votes csv from weaver
2 parents b3ca7b3 + 24c0057 commit 0a3344c

File tree

9 files changed

+32
-230
lines changed

9 files changed

+32
-230
lines changed

tools/cfp-vote-counter/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ aws sso login
2525
2626
# Generate CSV
2727
./main.py generate_csv cndt2022 [stg]
28-
29-
# Show time-series graph
30-
./main.py time_series cndt2022 [stg]
3128
```
3229

3330
Help
3431

3532
```
36-
./main.py generate -h
33+
./main.py generate_csv -h
3734
```

tools/cfp-vote-counter/main.py

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,51 @@
11
#!/usr/bin/env python3
2-
from typing import Literal, Optional
2+
from typing import Final, Literal, Optional
33

44
import fire
55
import pandas as pd
66
import matplotlib.pyplot as plt
77

8-
from src.query import QueryConfig, fetch_votes, Boto3Config
9-
from src.transform import unique_over_time, count_votes, time_series_total_count
8+
from gql import gql, Client
9+
from gql.transport.aiohttp import AIOHTTPTransport
10+
11+
12+
DKW_ENDPOINT: Final[dict[str, str]] = {
13+
"stg": "https://dkw.dev.cloudnativedays.jp/query",
14+
"prd": "https://dkw.cloudnativedays.jp/query",
15+
}
1016

1117

1218
class Command:
1319
"""CFP Vote Counter CLI"""
1420

15-
def generate_csv(self, event: str, env: Literal["stg", "prd"] = "prd", span: int = 3600,
16-
region: Optional[str] = None):
21+
def generate_csv(self, event: str, env: Literal["stg", "prd"] = "prd"):
1722
"""
1823
Generate transformed CFP vote csv
1924
2025
:param event: Event Abbreviation (e.g. cndt2022)
2126
:param env: Environment (stg|prd)
22-
:param span: Seconds of span where multiple votes from the same GIP would be considered as the same one
23-
:param region: Region of Dynamo vote table
2427
"""
25-
conf = QueryConfig(event, env)
26-
boto3_conf = Boto3Config(region)
27-
res = fetch_votes(conf, boto3_conf)
28-
if res["Count"] == 0:
29-
print("No votes found.")
30-
return
3128

32-
df = pd.DataFrame(res["Items"])
33-
df = unique_over_time(df, span)
34-
sr = count_votes(df)
35-
print(sr.to_csv())
36-
37-
def time_series(self, event: str, env: Literal["stg", "prd"] = "prd", span: int = 3600,
38-
region: Optional[str] = None, file: str = None):
39-
"""
40-
Generate transformed CFP vote csv
29+
transport = AIOHTTPTransport(url=DKW_ENDPOINT[env])
30+
client = Client(transport=transport, fetch_schema_from_transport=True)
4131

42-
:param event: Event Abbreviation (e.g. cndt2022)
43-
:param env: Environment (stg|prd)
44-
:param span: Seconds of span where multiple votes from the same GIP would be considered as the same one
45-
:param region: Region of Dynamo vote table
46-
:param file: File name of time-series graph figure
32+
query = gql(
4733
"""
48-
conf = QueryConfig(event, env)
49-
boto3_conf = Boto3Config(region)
50-
res = fetch_votes(conf, boto3_conf)
51-
if res["Count"] == 0:
52-
print("No votes found.")
53-
return
54-
55-
df = pd.DataFrame(res["Items"])
56-
df = unique_over_time(df, span)
57-
df = time_series_total_count(df, span)
58-
print(df)
59-
df.plot()
60-
if file:
61-
plt.savefig(file)
62-
else:
63-
plt.show()
34+
query getVoteCounts($confName: ConfName!){
35+
voteCounts(confName: $confName) {
36+
talkId
37+
count
38+
}
39+
}
40+
""")
41+
42+
data = client.execute(query, {"confName": event})
43+
df = (
44+
pd.DataFrame(data["voteCounts"])
45+
.sort_values(["count", "talkId"], ascending=[False, True])
46+
.reset_index(drop=True)
47+
)
48+
print(df.to_csv())
6449

6550

6651
if __name__ == "__main__":
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
boto3
21
pandas
32
pytest
43
fire
5-
matplotlib
4+
matplotlib
5+
gql
6+
aiohttp

tools/cfp-vote-counter/src/__init__.py

Whitespace-only changes.

tools/cfp-vote-counter/src/query.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

tools/cfp-vote-counter/src/test_query.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

tools/cfp-vote-counter/src/test_transform.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

tools/cfp-vote-counter/src/transform.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

tools/cfp-vote-counter/src/types.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)