Skip to content

Commit

Permalink
determine rounding based on threshold for credit (#4)
Browse files Browse the repository at this point in the history
* determine rounding based on threshold for credit
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Mar 17, 2022
1 parent 5064a02 commit c75b9d2
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip. Only major versions will be released as tags on GitHub.

## [0.0.x](https://github.com/vsoch/citelang/tree/main) (0.0.x)
- first release, and do rounding based on credit (0.0.1)
- skeleton release (0.0.0)
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![PyPI version](https://badge.fury.io/py/citelang.svg)](https://badge.fury.io/py/citelang)

![https://raw.githubusercontent.com/vsoch/citelang/main/docs/assets/img/citelang-tree.png](https://raw.githubusercontent.com/vsoch/citelang/main/docs/assets/img/citelang-tree.png)

Welcome to CiteLang! This is the first markdown syntax for citing software. Importantly,
when you use CiteLang to reference software.

Expand Down Expand Up @@ -241,7 +243,7 @@ $ citelang graph pypi requests

This will print a (much prettier) rendering of the graph to the console! Here is for pypi:

![examples/console/citelang-console-pypi.png](examples/console/citelang-console-pypi.png)
![https://raw.githubusercontent.com/vsoch/citelang/main/examples/console/citelang-console-pypi.png](https://raw.githubusercontent.com/vsoch/citelang/main/examples/console/citelang-console-pypi.png)

And citelang has custom package parsers, meaning we can add package managers that aren't in libraries.io!
Here is spack:
Expand All @@ -250,14 +252,14 @@ Here is spack:
$ citelang graph spack caliper
```

![examples/console/citelang-console-spack.png](examples/console/citelang-console-spack.png)
![https://raw.githubusercontent.com/vsoch/citelang/main/examples/console/citelang-console-spack.png](https://raw.githubusercontent.com/vsoch/citelang/main/examples/console/citelang-console-spack.png)

And GitHub.

```bash
$ citelang graph github singularityhub/singularity-hpc
```
![examples/console/citelang-console-github.png](examples/console/citelang-console-github.png)
![https://raw.githubusercontent.com/vsoch/citelang/main/examples/console/citelang-console-github.png](https://raw.githubusercontent.com/vsoch/citelang/main/examples/console/citelang-console-github.png)

GitHub is a bit of a deviant parser because we use the dendency graph that GitHub has found in your repository.
If you have a non-traditional way of defining deps (e.g., singularity-cli above writes them into a version.py that gets piped into setup.py) they won't show up. Also note that when you cite GitHub, we are giving credit to ALL the software you use for your setup, including documentation and CI. Here is a more traditional GitHub repository
Expand Down Expand Up @@ -316,8 +318,7 @@ MATCH (n) RETURN (n)

You should see:


![examples/cypher/graph.png](examples/cypher/graph.png)
![https://raw.githubusercontent.com/vsoch/citelang/main/examples/cypher/graph.png](https://raw.githubusercontent.com/vsoch/citelang/main/examples/cypher/graph.png)

From within Python you can do:

Expand Down Expand Up @@ -369,7 +370,7 @@ nx.draw(graph, with_labels=True, font_weight='bold')
plt.show()
```

That should generate [examples/gexf/graph.xml](examples/gexf/graph.xml).
That should generate [examples/gexf/graph.xml](https://raw.githubusercontent.com/vsoch/citelang/main/examples/gexf/graph.xml).


### Render
Expand Down
9 changes: 8 additions & 1 deletion citelang/main/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ def _graph(
seen = set()

# Top node gets full credit 1.0 (to split between itself and deps)
root = graph.Node(obj=pkg, weight=1.0, credit_split=credit_split, depth=0)
root = graph.Node(
obj=pkg,
weight=1.0,
credit_split=credit_split,
depth=0,
min_credit=min_credit,
)

# A pointer to the next node
next_nodes = [root]
Expand Down Expand Up @@ -184,6 +190,7 @@ def _graph(
weight=dep_credit,
credit_split=credit_split,
depth=next_node.depth + 1,
min_credit=min_credit,
)
next_node.add_child(child)
next_nodes.append(child)
Expand Down
10 changes: 9 additions & 1 deletion citelang/main/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class Node:
def __init__(self, obj, weight, credit_split=0.5, depth=0):
def __init__(self, obj, weight, credit_split=0.5, depth=0, min_credit=0.01):
"""
A graph node has a name (or object), weight, and children
"""
Expand All @@ -13,6 +13,7 @@ def __init__(self, obj, weight, credit_split=0.5, depth=0):
self.children = []
self.credit_split = credit_split
self.depth = depth
self.min_credit = min_credit

# If we stop parsing we can set this credit to whatever the node and
# children would originall get
Expand All @@ -22,6 +23,13 @@ def __init__(self, obj, weight, credit_split=0.5, depth=0):
def name(self):
return self.obj.name

@property
def round_by(self):
value = str(self.min_credit).split(".", 1)[-1]
if not value:
return 3
return len(value)

def add_child(self, child):
"""
Add child ensures we increment the depth by 1
Expand Down
19 changes: 13 additions & 6 deletions citelang/main/graph/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@

# Randomly select an AMAZING icon
# Note some of these require TWO spaces after the icon to render properly!
icons = ["⭐️ ", "✨️ ", "💛️ ", "🔷️ ", "❤️ ", "💜️ ", "🧡️ ", "💗️ ", "🔴️ ", "♦️ ", "🔶️ "]
# The faded heart is my favorite, so we want it 1/2 the time
icons = ["⭐️ ", "✨️ ", "💛️ ", "🔷️ ", "❤️ ", "💜️ ", "🧡️ ", "🔴️ ", "♦️ ", "🔶️ "] + [
"💗️ "
] * 10
root_icons = ["🦄️", "☕️", "🤓️", "⭐️"]


def print_tree(root):
node = Text(f"🦄️ {root.name}", "bold magenta")
credit = round(root.credit, 3)

# Randomly select icons
icon = random.choice(icons)
root_icon = random.choice(root_icons)

node = Text(f"{root_icon} {root.name}", "bold magenta")
credit = round(root.credit, root.round_by)
node.append(f" ({credit})", "blue")
tree = Tree(
node,
guide_style="bold bright_blue",
)

# Randomly select icons
icon = random.choice(icons)
generate_tree(root, tree=tree, icon=icon)
print(tree)

Expand All @@ -33,7 +40,7 @@ def generate_tree(next_node, icon, tree=None) -> None:
"""
for child in next_node.children:
# We won't have a tree on the first run
credit = round(child.credit, 3)
credit = round(child.credit, child.round_by)
node = Text(child.name, "green")
node.highlight_regex(r"\..*$", "bold red")
node.stylize(f"link file://{child.name}")
Expand Down
8 changes: 7 additions & 1 deletion citelang/main/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def parse_data(self):
"name": self.result.name,
"credit": self.result.credit,
"weight": self.result.weight,
"round_by": self.result.round_by,
"children": [],
}

Expand All @@ -217,6 +218,7 @@ def add(data, children, total):
"name": child.name,
"credit": child.credit,
"weight": child.weight,
"round_by": child.round_by,
"children": [],
}
total = add(child, node["children"], total)
Expand All @@ -235,7 +237,11 @@ def print_result(self):
def print_result(result, indent=2):
print(
"%s%20s: %s"
% (" " * indent, result["name"], round(result["credit"], 3))
% (
" " * indent,
result["name"],
round(result["credit"], result["round_by"]),
)
)
for child in result["children"]:
print_result(child, indent=indent * 2)
Expand Down
2 changes: 1 addition & 1 deletion citelang/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__copyright__ = "Copyright 2022, Vanessa Sochat"
__license__ = "MPL 2.0"

__version__ = "0.0.0"
__version__ = "0.0.1"
AUTHOR = "Vanessa Sochat"
EMAIL = "vsoch@users.noreply.github.com"
NAME = "citelang"
Expand Down
Binary file added docs/assets/img/citelang-tree.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c75b9d2

Please sign in to comment.