Skip to content

Commit

Permalink
Close hi-primus#599 : External CSS to Inline CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarrioja committed Aug 5, 2019
1 parent de5aeef commit 53fb535
Show file tree
Hide file tree
Showing 10 changed files with 840 additions and 57 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ readme/data/foo\.json/
readme/data/foo\.parquet/

readme/data/foo\.csv/

#nodeJS

node_modules
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ op.output("html")

Optimus comes with a powerful and unique data profiler. Besides basic and advance stats like min, max, kurtosis, mad etc,
it also let you know what type of data has every column. For example if a string column have string, integer, float, bool, date Optimus can give you an unique overview about your data.
Just run `df.profile("*")` to profile all the columns. For more info about the profiler please go to this [notebook](../examples/profiler.ipynb).
Just run `df.profile("*")` to profile all the columns. For more info about the profiler please go to this [notebook](./examples/profiler.ipynb).

Let's load a "big" dataset

Expand Down
32 changes: 22 additions & 10 deletions README_for_devs.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,64 @@
# Hacking Optimus

##Windows
##Windows

If you want to contribute, hack or play with Optimus you are in the raight place. This is a little guide to
If you want to contribute, hack or play with Optimus you are in the raight place. This is a little guide to

* Install Jupyter Notebooks
- Install Jupyter Notebooks

Download anaconda from https://www.anaconda.com/download/ and run the file

* Clone the Repo and install requirements
- Clone the Repo and install requirements

Go to the folder you want to download de repo and run:

`git clone https://github.com/ironmussa/Optimus.git`
`git clone https://github.com/ironmussa/Optimus.git`

The install the requirements

`pip install -r requirements.txt`

* Install Spark
- Install Spark

Go to http://spark.apache.org/downloads.html and download Spark 2.3.1 with Pre-built Hadoop 2.7
Decompress the file in c:\opt\spark

* Install java
- Install java

First, install chocolatey https://chocolatey.org/install#installing-chocolatey
>> Chocolatey needs Administrative permission.

> > Chocolatey needs Administrative permission.
Then from the command line
`choco install jdk8`

## Set vars

Be sure that the Spark version is the same that you download

`setx SPARK_HOME C:\opt\spark\spark-2.3.1-bin-hadoop2.7`

Check in the console if python is run as 'python','python3' etc. Use the one you found to set PYSPARK_PYTHON
`setx PYSPARK_PYTHON python`

Open the examples folder in the cloned Optimus repo and go to hack_optimus.ipyn. There you are going fo find some tips
Open the examples folder in the cloned Optimus repo and go to hack_optimus.ipyn. There you are going fo find some tips
to hack and contribute with Optimus

## Troubleshooting

Error: you do not have permission to tmp\hive
from anaconda
from anaconda
wintools.exe ls c:\tmp\hive
wintools.exe chmod 777 c:\tmp\hive

## Processing CSS

To add and external CSS file to the templates html as inline CSS

- Install NodeJS

Go to https://nodejs.org and download and install Node JS

- Run `npm install`

- Run `node inlinecss.js`
62 changes: 62 additions & 0 deletions inlinecss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var fs = require('fs');
var juice = require('juice');

/*CSS*/
var sourceCss = fs.readFileSync('optimus/css/styles.css', 'utf-8');

/*HTML to READ*/
var oneColumn = fs.readFileSync(
'optimus/profiler/templates/one_column.html',
'utf-8',
);
var generalInfo = fs.readFileSync(
'optimus/profiler/templates/general_info.html',
'utf-8',
);
var table = fs.readFileSync('optimus/templates/table.html', 'utf-8');

/** ADD STYLE TAG & CONCAT TO THE FILE */
var inlineCssOneColumn = juice('<style>' + sourceCss + '</style>' + oneColumn, {
removeStyleTags: true,
preserveMediaQueries: true,
});
var inlineCssGeneralInfo = juice(
'<style>' + sourceCss + '</style>' + generalInfo,
{ removeStyleTags: true, preserveMediaQueries: true },
);
var inlineCssTable = juice('<style>' + sourceCss + '</style>' + table, {
removeStyleTags: true,
preserveMediaQueries: true,
});

/** CREATE A INLINE-CSS HTML FILE */
fs.writeFile(
'optimus/profiler/templates/build/one_column.html',
inlineCssOneColumn,
function(err) {
if (err) throw err;
console.log(
'File is created successfully in "optimus/profiler/templates/build/one_column.html"',
);
},
);

fs.writeFile(
'optimus/profiler/templates/build/general_info.html',
inlineCssGeneralInfo,
function(err) {
if (err) throw err;
console.log(
'File is created successfully in "optimus/profiler/templates/build/general_info.html"',
);
},
);

fs.writeFile('optimus/templates/build/table.html', inlineCssTable, function(
err,
) {
if (err) throw err;
console.log(
'File is created successfully in "optimus/templates/build/table.html"',
);
});
2 changes: 1 addition & 1 deletion optimus/dataframe/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def table_html(self, limit=10, columns=None, title=None, full=False):
data = collect_as_dict(self.cols.select(columns).limit(limit))

# Load the Jinja template
template_loader = jinja2.FileSystemLoader(searchpath=absolute_path("/templates"))
template_loader = jinja2.FileSystemLoader(searchpath=absolute_path("/templates/build"))
template_env = jinja2.Environment(loader=template_loader, autoescape=True)
template = template_env.get_template("table.html")

Expand Down
19 changes: 1 addition & 18 deletions optimus/optimus.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,10 @@ def __init__(self, session=None, master="local[*]", app_name="optimus", checkpoi
)
self.ml = ML()

#
self._load_css()

# Set global output as html
self.output("html")

@staticmethod
def _load_css():
"""
Try to load the css for templates
:return:
"""
try:
if __IPYTHON__:
url = absolute_path("/css/styles.css")
styles = open(url, "r", encoding="utf8").read()
s = '<style>%s</style>' % styles
print_html(s)
except NameError:
pass


@staticmethod
def connect(db_type="redshift", host=None, database=None, user=None, password=None, port=None, schema="public",
oracle_tns=None, oracle_service_name=None, oracle_sid=None):
Expand Down
3 changes: 1 addition & 2 deletions optimus/profiler/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ def run(self, df, columns, buckets=40, infer=False, relative_error=1, approx_cou
output = Profiler.to_json(df, columns, buckets, infer, relative_error, approx_count)

# Load jinja
path = os.path.dirname(os.path.abspath(__file__))
template_loader = jinja2.FileSystemLoader(searchpath=path + "//templates")
template_loader = jinja2.FileSystemLoader(searchpath=absolute_path("/profiler/templates/build"))
template_env = jinja2.Environment(loader=template_loader, autoescape=True)

# Render template
Expand Down
25 changes: 0 additions & 25 deletions optimus/profiler/templates/summary.html

This file was deleted.

Loading

0 comments on commit 53fb535

Please sign in to comment.