Skip to content

Commit 98ab68b

Browse files
author
Joseph Damiba
committed
making sure order of financial posts is consecutive
1 parent 89994fb commit 98ab68b

33 files changed

+359
-251
lines changed

check-or-enforce-order.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import frontmatter as fm
2+
from pathlib import Path, PosixPath
3+
import sys
4+
5+
# path here is intended to include only posts from a single language
6+
# _posts/r, _posts/plotly_js, _posts/python-v3, _posts/python in 'documentation'
7+
# build/html in 'plotly.py-docs'
8+
try:
9+
folder_path = str(sys.argv[1])
10+
except:
11+
raise Exception("You need to specify a path!")
12+
13+
# check to see if enforce flag was given at command line
14+
enforce = False
15+
if len(sys.argv) == 3:
16+
if sys.argv[2] == 'enforce':
17+
enforce = True
18+
19+
categories = ["file_settings", "basic", "financial", "statistical", "scientific", "maps", "3d_charts", "multiple_axes"]
20+
21+
def get_post(path):
22+
return fm.load(str(path))
23+
24+
def get_front_matter(post):
25+
if "jupyter" in post.metadata:
26+
return post["jupyter"]["plotly"]
27+
else:
28+
return post.metadata
29+
30+
# this function will mutate the front-matter to enforce a sequential order
31+
def enforceOrder(list_to_be_ordered):
32+
print(list_to_be_ordered)
33+
for index, post in enumerate(list_to_be_ordered):
34+
post_to_be_altered = fm.load(post)
35+
if folder_path == "python": # accounts for the fact that this is also run in the plotly.py-docs repo
36+
post_to_be_altered.metadata["jupyter"]["plotly"]['order'] = (index+2 if index>=4 else index+1)
37+
fm.dump(post_to_be_altered, post)
38+
else:
39+
post_to_be_altered.metadata['order'] = index+1
40+
fm.dump(post_to_be_altered, post)
41+
42+
def is_consecutive(list_to_be_checked):
43+
if folder_path in ["python", "build/html", "r", "build"] and len(list_to_be_checked) > 0:
44+
list_to_be_checked = list_to_be_checked + [5]
45+
print(sorted(list_to_be_checked))
46+
return sorted(list_to_be_checked) == list(range(1, len(list_to_be_checked)+1))
47+
48+
def validate_front_matter(front_matter):
49+
if len(front_matter.keys()) > 0:
50+
if "display_as" in front_matter and "order" in front_matter:
51+
if front_matter['display_as'] in categories:
52+
return True
53+
else:
54+
return False
55+
else:
56+
return False
57+
58+
def get_paths_and_orders_by_category():
59+
posts_by_category = {category: dict(orders=[], paths=[]) for category in categories}
60+
suffixes = ["md", "html"]
61+
if folder_path == "r":
62+
suffixes = ["Rmd"]
63+
for suffix in suffixes:
64+
for path in Path(folder_path).glob("**/*."+suffix):
65+
if ".ipynb_checkpoints" not in str(path):
66+
post = get_post(path)
67+
front_matter = get_front_matter(post)
68+
if "display_as" in front_matter:
69+
post_category = front_matter['display_as']
70+
if post_category in posts_by_category and validate_front_matter(front_matter):
71+
posts_by_category[post_category]["paths"].append(path)
72+
posts_by_category[post_category]["orders"].append(front_matter['order'])
73+
return posts_by_category
74+
75+
def check_order():
76+
posts_by_category = get_paths_and_orders_by_category()
77+
for category in categories:
78+
print(category)
79+
orders = posts_by_category[category]["orders"]
80+
paths = posts_by_category[category]["paths"]
81+
sorted_paths = [path for order, path in sorted(zip(orders, paths))]
82+
if not is_consecutive(posts_by_category[category]["orders"]):
83+
print("Order is not sequential! **CHECK NOT PASSED** in '{}' display_as!".format(category))
84+
if enforce is True:
85+
print("ENFORCING CORRECT ORDER! for {}\n".format(category))
86+
enforceOrder(sorted_paths)
87+
else:
88+
arg = folder_path
89+
if folder_path == "build/html":
90+
arg = "python"
91+
if folder_path == "build":
92+
arg = "r"
93+
raise Exception("Order is not sequential! **CHECK NOT PASSED** in '{}' display_as! Run 'python check-or-enforce-order.py {} enforce' to resolve!".format(category, arg))
94+
else:
95+
print("*Check Passed!*\n")
96+
97+
print("**********************************************")
98+
print("Order of '{}' Before Enforcing!".format(folder_path))
99+
print("**********************************************\n")
100+
101+
check_order()
102+
103+
if enforce is True:
104+
print("*******************************************")
105+
print("Order of '{}' After Enforcing!".format(folder_path))
106+
print("*******************************************\n")
107+
check_order()

r/2015-07-30-3d-line-plots.Rmd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
2-
name: 3D Line Plots
3-
permalink: r/3d-line-plots/
42
description: How to make interactive 3D line plots in R.
5-
layout: base
6-
thumbnail: thumbnail/3d-line.jpg
7-
language: r
8-
page_type: example_index
93
display_as: 3d_charts
4+
language: r
5+
layout: base
6+
name: 3D Line Plots
107
order: 2
118
output:
129
html_document:
1310
keep_md: true
11+
page_type: example_index
12+
permalink: r/3d-line-plots/
13+
thumbnail: thumbnail/3d-line.jpg
1414
---
1515

1616
```{r, echo = FALSE, message=FALSE}
@@ -137,4 +137,4 @@ p
137137

138138
#Reference
139139

140-
See [https://plot.ly/r/reference/#scatter3d](https://plot.ly/r/reference/#scatter3d) for more information and chart attribute options!
140+
See [https://plot.ly/r/reference/#scatter3d](https://plot.ly/r/reference/#scatter3d) for more information and chart attribute options!

r/2015-07-30-3d-scatter-plots.Rmd

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
2-
name: 3D Scatter Plots
3-
permalink: r/3d-scatter-plots/
42
description: How to make interactive 3D scatter plots in R.
5-
layout: base
6-
thumbnail: thumbnail/3d-scatter.jpg
7-
language: r
8-
page_type: example_index
93
display_as: 3d_charts
10-
order: 0
4+
language: r
5+
layout: base
6+
name: 3D Scatter Plots
7+
order: 1
118
output:
129
html_document:
1310
keep_md: true
11+
page_type: example_index
12+
permalink: r/3d-scatter-plots/
13+
thumbnail: thumbnail/3d-scatter.jpg
1414
---
1515

1616
```{r, echo = FALSE, message=FALSE}
@@ -117,6 +117,4 @@ p
117117

118118
#Reference
119119

120-
See [https://plot.ly/r/reference/#scatter3d](https://plot.ly/r/reference/#scatter3d) for more information and chart attribute options!
121-
122-
120+
See [https://plot.ly/r/reference/#scatter3d](https://plot.ly/r/reference/#scatter3d) for more information and chart attribute options!

r/2015-07-30-3d-surface-plots.Rmd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
2-
name: 3D Surface Plots
3-
permalink: r/3d-surface-plots/
42
description: How to make interactive 3D surface plots in R.
5-
layout: base
6-
thumbnail: thumbnail/3d-surface.jpg
7-
language: r
8-
page_type: example_index
93
display_as: 3d_charts
10-
order: 5
4+
language: r
5+
layout: base
6+
name: 3D Surface Plots
7+
order: 3
118
output:
129
html_document:
1310
keep_md: true
11+
page_type: example_index
12+
permalink: r/3d-surface-plots/
13+
thumbnail: thumbnail/3d-surface.jpg
1414
---
1515

1616
```{r, echo = FALSE, message=FALSE}
@@ -107,4 +107,4 @@ p <- plot_ly(showscale = FALSE) %>%
107107
add_surface(z = ~z3, opacity = 0.98)
108108
109109
p
110-
```
110+
```

r/2015-07-30-bubble-maps.Rmd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
2-
name: Bubble Maps
3-
permalink: r/bubble-maps/
42
description: How to make a bubble chart and map in R.
5-
layout: base
6-
thumbnail: thumbnail/bubble-map.jpg
7-
language: r
8-
page_type: example_index
93
display_as: maps
4+
language: r
5+
layout: base
6+
name: Bubble Maps
107
order: 5
118
output:
129
html_document:
1310
keep_md: true
11+
page_type: example_index
12+
permalink: r/bubble-maps/
13+
thumbnail: thumbnail/bubble-map.jpg
1414
---
1515

1616
```{r, echo = FALSE, message=FALSE}
@@ -61,4 +61,4 @@ p <- plot_geo(df, locationmode = 'USA-states', sizes = c(1, 250)) %>%
6161
layout(title = '2014 US city populations<br>(Click legend to toggle)', geo = g)
6262
6363
p
64-
```
64+
```

r/2015-07-30-choropleth.Rmd

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
2-
name: Choropleth Maps
3-
permalink: r/choropleth-maps/
4-
description: How to make a choropleth map in R. A choropleth map shades geographic regions by value.
5-
layout: base
6-
thumbnail: thumbnail/choropleth.jpg
7-
language: r
8-
page_type: example_index
2+
description: How to make a choropleth map in R. A choropleth map shades geographic
3+
regions by value.
94
display_as: maps
10-
order: 0
5+
language: r
6+
layout: base
7+
name: Choropleth Maps
8+
order: 1
119
output:
1210
html_document:
1311
keep_md: true
12+
page_type: example_index
13+
permalink: r/choropleth-maps/
14+
thumbnail: thumbnail/choropleth.jpg
1415
---
1516

1617
```{r, echo = FALSE, message=FALSE}
@@ -152,4 +153,4 @@ p <- df %>%
152153
)
153154
154155
p
155-
```
156+
```

r/2015-07-30-contour-plots.Rmd

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
2-
name: Contour Plots
3-
permalink: r/contour-plots/
4-
description: How to make a contour plot in R. Two examples of contour plots of matrices and 2D distributions.
5-
layout: base
6-
thumbnail: thumbnail/contour.jpg
7-
language: r
8-
page_type: u-guide
2+
description: How to make a contour plot in R. Two examples of contour plots of matrices
3+
and 2D distributions.
94
display_as: scientific
10-
order: 6
5+
language: r
6+
layout: base
7+
name: Contour Plots
8+
order: 2
119
output:
1210
html_document:
1311
keep_md: true
12+
page_type: u-guide
13+
permalink: r/contour-plots/
14+
thumbnail: thumbnail/contour.jpg
1415
---
1516

1617
```{r, echo = FALSE, message=FALSE}
@@ -211,4 +212,4 @@ See [here](https://plot.ly/r/colorscales/) for more examples concerning colorsca
211212

212213
### Reference
213214

214-
See [https://plot.ly/r/reference/#contour](https://plot.ly/r/reference/#contour) for more information and chart attribute options!
215+
See [https://plot.ly/r/reference/#contour](https://plot.ly/r/reference/#contour) for more information and chart attribute options!

r/2015-07-30-heatmaps.Rmd

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
2-
name: Heatmaps
3-
permalink: r/heatmaps/
4-
description: How to make a heatmap in R with a matrix. Seven examples of colored and labeled heatmaps with custom colorscales.
5-
layout: base
6-
thumbnail: thumbnail/heatmap.jpg
7-
language: r
8-
page_type: u-guide
2+
description: How to make a heatmap in R with a matrix. Seven examples of colored and
3+
labeled heatmaps with custom colorscales.
94
display_as: scientific
10-
order: 7
5+
language: r
6+
layout: base
7+
name: Heatmaps
8+
order: 3
119
output:
1210
html_document:
1311
keep_md: true
12+
page_type: u-guide
13+
permalink: r/heatmaps/
14+
thumbnail: thumbnail/heatmap.jpg
1415
---
1516

1617
```{r, echo = FALSE, message=FALSE}
@@ -84,5 +85,4 @@ colz <- setNames(data.frame(vals[o], cols[o]), NULL)
8485
p <- plot_ly(z = volcano, colorscale = colz, type = "heatmap")
8586
8687
p
87-
```
88-
88+
```

r/2015-07-30-line-plot-maps.Rmd

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
---
2-
name: Lines on Maps
3-
permalink: r/lines-on-maps/
4-
description: How to draw lines, great circles, and contours on maps in R. Lines on maps can show distance between geographic points or be contour lines (isolines, isopleths, or isarithms).
5-
layout: base
6-
thumbnail: thumbnail/flight-paths.jpg
7-
language: r
8-
page_type: example_index
2+
description: How to draw lines, great circles, and contours on maps in R. Lines on
3+
maps can show distance between geographic points or be contour lines (isolines,
4+
isopleths, or isarithms).
95
display_as: maps
10-
order: 3
6+
language: r
7+
layout: base
8+
name: Lines on Maps
9+
order: 4
1110
output:
1211
html_document:
1312
keep_md: true
13+
page_type: example_index
14+
permalink: r/lines-on-maps/
15+
thumbnail: thumbnail/flight-paths.jpg
1416
---
1517

1618
```{r, echo = FALSE, message=FALSE}
@@ -158,4 +160,4 @@ p <- plot_geo(d) %>%
158160
)
159161
160162
p
161-
```
163+
```

r/2015-07-30-log-plot.Rmd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
2-
name: Log Plots
3-
permalink: r/log-plot/
42
description: How to make a plot with logarithmic axes in R.
5-
layout: base
6-
thumbnail: thumbnail/log.jpg
7-
language: r
83
display_as: scientific
9-
order: 0
4+
language: r
5+
layout: base
6+
name: Log Plots
7+
order: 1
108
output:
119
html_document:
1210
keep_md: true
11+
permalink: r/log-plot/
12+
thumbnail: thumbnail/log.jpg
1313
---
1414

1515
```{r, echo = FALSE, message=FALSE}
@@ -48,4 +48,4 @@ p <- layout(p, xaxis = list(type = "log"),
4848
yaxis = list(type = "log"))
4949
5050
p
51-
```
51+
```

0 commit comments

Comments
 (0)