Skip to content

Instantly share code, notes, and snippets.

@jf-parent
Created December 15, 2016 10:40
Show Gist options
  • Save jf-parent/8c02ee073c34b01ad494aec34b3a3697 to your computer and use it in GitHub Desktop.
Save jf-parent/8c02ee073c34b01ad494aec34b3a3697 to your computer and use it in GitHub Desktop.
import sys
import os
from dateutil.parser import parse
HERE = os.path.abspath('/home/ubuntu/crm/')
ROOT = os.path.join(HERE)
sys.path.append(ROOT)
from server.settings import config
# Let take the leads_status for example
# visual specs: https://goo.gl/photos/x2M3DkcjMcFodJrn6
# We have 6 differents options:
# [*] date_from (string["%d/%m/%y"]) => from the date
# [*] date_to (string["%d/%m/%y"]) => to the date
# [*] source (string[choices[a, b, c, ...]]) => the source of the data
# [*] campaign (string[choices[a, b, c, ...]]) => the campaign name
# [*] Ad content (string[choices[a, b, c, ...]]) => the ad content
# [*] keyword (string[choices[a, b, c, ...]]) => the keyword
def leads_status(date_from, date_to, source, campaign, ad_content, keyword):
layout = {
'title': 'Leads selon leur statut',
'xaxis': {
'title': 'Date de création des leads (en semaine)',
},
'yaxis': {
'title': 'Pourcentage cumulatif des leads',
'range': [0, 1]
}
}
config.configure()
session = get_session(config)
# Parse the date string to create a datetime object
from_date = parse(date_from)
to_date = parse(date_to)
# DATA
# pipeline = [...]
# pipeline_res_1 = list(session.db.Contact.aggregate(pipeline))
# [...]
data = [data1, data2, data3]
# RESULT
graph = {'graph_type': 'bar', 'layout': layout, 'data': data}
return graph
data = leads_status('11/02/2016', '19/02/2016', 'ga', '1', 'all')
print(data)
>>> {'graph_type': 'bar', 'layout': {...}, 'data': {...}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment