-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdocsgen.py
80 lines (60 loc) · 1.9 KB
/
docsgen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This file is part of tindicators, licensed under GNU LGPL v3.
# Author: Ilya Pikulin <[email protected]>, 2020
import yaml
import time
import os
import argparse
import glob
from version import version
parser = argparse.ArgumentParser(description='Generate the docs for tindicators')
parser.add_argument('outfile', default='index.markdown')
args = parser.parse_args()
build = int(time.time())
path_prefix = os.path.join(os.path.dirname(os.path.realpath(__file__)), '')
indicators = yaml.safe_load(open(path_prefix+'indicators.yaml', encoding='utf8'))
outfile = open(path_prefix+args.outfile, 'w')
outfile.write('''\
---
layout: page
title: Documentation
---
## Quick start
```bash
pip install tindicators
```
```python
from tindicators import ti
```
Example usage:
```python
>>> import numpy as np
>>> ti.sma(np.arange(10), 3)
array([nan, nan, 1., 2., 3., 4., 5., 6., 7., 8.])
```
## List of available indicators
There are currently **{num} indicators** available in [tindicators](https://github.com/3jane/tindicators) v{version}.
'''.format(num=len(indicators), version=version))
for indicator in indicators.items():
name, (elab_name, type, inputs, options, outputs, features, source) = indicator
tab = ' '*4
nl = '\n'
inputs_str = f',{nl}{tab}'.join([x+': np.ndarray' for x in inputs])
options_str = f',{nl}{tab}'.join([x+'' for x in options])
params_str = f',{nl}{tab}'.join([inputs_str, options_str]) \
if (inputs_str and options_str) \
else (inputs_str or options_str)
outputs_str = f',{nl}{tab}'.join([x+' = np.ndarray' for x in outputs])
filename = os.path.basename(list(glob.glob(path_prefix+f'indicators/{name}.*'))[0])
outfile.write(f'''
#### {elab_name}
*Source:* {source} <br/>
*Implementation:* [{filename}](https://github.com/3jane/tindicators/blob/master/indicators/{filename}) <br/>
*Signature:*
```python
ti.{name}(
{params_str}
) -> NamedTuple(...,
{outputs_str}
)
```
''')