Git Product home page Git Product logo

spendingstories's Introduction

Spending Stories

2013, Journalism++
GNU General Public License

Build Status

Overview

  1. How to install Spending Stories
  2. Presentation of the application
  3. How to customize Spending Stories
  4. How to translate Spending Stories
  5. Update stories with last currencies and cpi

How to install Spending Stories

Important notes

This installation guide was created for and tested on Debian/Ubuntu operating systems.

If you find a bug/error in this guide please submit a pull request.

Overview

The Spending Stories installation consists of setting up the following components:

  1. Set up your python environment
  2. Install dependencies
  3. Set up the database (example with MySQL)
  4. Run server (example with mod_wsgi from apache)
  5. Set up your superuser

1. Set up your python environment

a. Install python packages:

sudo apt-get install build-essential git-core python python-pip python-dev

b. Install virtualenv a tool to isolate your dependencies

sudo pip install virtualenv

c. Download the project

git clone https://github.com/jplusplus/okf-spending-stories.git

d. Create the virtualenv folder for this project

Every python dependencies will be installed in this folder to keep your system's environment clean.

cd okf-spending-stories
virtualenv venv --no-site-packages --distribute --prompt=SpendingStories

e. Activate your new virtualenv

source .env

Tips: you can install autoenv to source this file automatically each time you cd this folder.

2. Install dependencies

a. Install python modules required

pip install -r requirements_core.txt

b. Install compilers for Less and CoffeeScript

If you don't already have nodejs installed:

sudo apt-get update
sudo apt-get install python-software-properties g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

and then install them

npm install

3. Set up the database

a. Configure the file webapp/settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME'    : 'dev.db', # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER'    : '',
        'PASSWORD': '',
        'HOST'    : '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT'    : '', # Set to empty string for default.
    }
}

Currently, the dataset backend is sqlite3, very easy to use for development. You can change it by mysql, postgres or oracle.
Documentation

Example with MySQL

For MySQL, you will need to install mysql-python, like that:

sudo apt-get install libmysqlclient-dev
pip install mysql-python

and create the database

mysql -u root -p
mysql>  CREATE DATABASE IF NOT EXISTS `<database_name>` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> \q

**b. Syncing the database **

To create the tables in the database and put some data like categories and currencies, please run and provide asked informations

python manage.py syncdb && python manage.py migrate

4. Run server

a. For development

python manage.py runserver

b. For production

You have a lot a choice to deploy this application.
Take a look on this documentation : Django - deployment

Keep in mind that assets are already served by the wsgi server with dj-static if you're using our wsgi.py file

Dependency:

sudo apt-get install libapache2-mod-wsgi

Please see the documentation about the deployement with mod_wsgi.

This is an Apache configuration that loads the virtualenv :

WSGIScriptAlias / /<PATH_TO_PROJECT>/webapp/wsgi.py
WSGIPythonPath /<PATH_TO_PROJECT>:/<PATH_TO_PROJECT>/venv/lib/python2.6/site-packages:/<PATH_TO_PROJECT>/libs

<Directory /<PATH_TO_PROJECT>/webapp>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

5. Set up your superuser

In order to add stories you have to configure your user base. If you already synced your database you must have been prompted to configure a superuser.

If you skipped this step then you have to run the following command:

python manage.py createsuperuser

Presentation of the application

Spending Stories is built with Django, a Python Web framework.

It's composed of :

  • a web application
  • an API (Available end-points listed on the page http://<domain_name>/api)
  • some scripts to update data (such as CPI data)

HTML pages are located in webapp/templates
Static files (css, javascript, images etc...) are located in webapp/static

How to customize Spending Stories

Spending Stories uses Twitter Bootstrap for its style.

Title

Spending Stories' title is defined in a translation variable: HEADER_APP_TITLE. However, if you want to change the HTML title tag, you have to manually modify it in webapp/templates/base.html.

Colors

Colors are defined in less variables. They can be overridden in webapp/static/less/base.less.

Notable variables:

  • body-bg: defines the page background
  • brand-primary: defines color for links, buttons and sticky cards' background
  • strat-main-color: defines the visualization background color
  • text-color: defines the color for most of the texts

Acceptable values are hexadecimal colors, rgb colors or HTML color names:

@body-bg: rgb(80, 80, 80);
@strat-main-color: #403F3F;
@text-color: black;

How to translate Spending Stories

The Spending Stories translation is focused on the front-end of the application. However we're also using the django default translation system to translate some string that come from the django application (the server) of this project.

The front-end translation system is composed of the following tools:

This part covers the following topics:

  • how to add/edit some translation
  • add a supported language
  • what is not fully translated for the moment

Add or edit translation

1. Add translation in the code/in the template files

You have to choose a translation key. We use the following naming convention:

  • the key must be in uppercase and underscore (e.g A_TRANSLATION_KEY)
  • the key describes what it translates and where.
    • the first part of the key is the name of the script or the template containing the key.
      Ex: a key in contribute.html will start by CONTRIBUTE_
    • the last part is the description of the content, or the word if it can be described otherwise.
      Ex: the translation key of the 'Compare' button contained in the header.html template will be HEADER_COMPARE_BUTTON

Note: the task for translation key collection is handled by a grunt task and therefore is really limited: it may not detect your translation keys for many reasons because of its design. To avoid that, here's some advice:

  1. Prefer filter notation over directive notation in your templates files:
    <!-- good: --> 
    <a href="">[[ 'MY_TRADUCTION' | translate ]]</a>
    <!-- not good: --> 
    <a href="" translate>MY_TRADUCTION</a>
  1. Avoid dynamic keys in your coffescript files and keep the dollar prefix
    # good 
    my_string = $translate('GOOD_KEY_IS_GOOD')
    # bad -> translate service is missing its dollar prefix, it will not detect this key
    my_string = translate('GOOD_KEY')
    # bad -> it's a dynamic key, scripts are not evaluated so it will not detect this key either
    my_key = 'GOOD_KEY_SEEMS_GOOD'
    my_string = $translate(my_key)
    

2. Launch python manage.py makemessages from the webapp folder

This will produce the collection of every translation keys contained in html, coffee & python files.

3. Update the new generated locales files

This files contains all the translation keys and their translation values, they're located at:

  • /webapp/static/locales/<locale code>.json for static application translations
  • /webapp/locale/<locale code>/LC_MESSAGES/django.po for the Django application translations

4. Compile the new Django messages with python manage.py compilemessages from the webapp folder

Add a language

If you want to support a new language in your Spending Stories instance you must change Django's settings. You must update the webapp/settings.py file and look for the LANGUAGES variable. This is where we store the list of supported languages, by default we only support English.

LANGUAGES = (
  ('en_GB', _('English')),
  # add your new language here
)

What is not fully translated

User query

User query comprehension works only in French & English for the moment. The way we understand the amounts and currencies entered by user is based on a fuzzy search. This means all terms that will be recognized have to be entered in an array. If you look at the getSearchSetData method in the Comprehension service you can see all translated term in our array.

This way of doing cannot work with German for instance because of the way most numbers are constructed. Fuzzy search can work but the search data set (the data that will be used to perform the search) has to be built by an algorithm because of the tremendous amount of numbers.

Update stories with last currencies and CPI

It's important to note that the conversion rates & the consumer price indexes we use to deal with inflation need to be refreshed by hand:

python manage.py update_currencies

spendingstories's People

Contributors

annelisebouyer avatar n-kb avatar paulloz avatar pbellon avatar pirhoo avatar roll avatar vied12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spendingstories's Issues

Remove useless currencies from currency list

As currencies are unevenly distributed, I'd suggest that we display only the first 50 currencies in the list (97% of global money), so as to have a cleaner dropdown list

The top 50 are:
CNY
JPY
USD
EUR
GBP
BRL
AUD
KRW
CAD
INR
CHF
HKD
TWD
RUB
MXN
THB
MYR
SEK
SGD
TRY
SAR
IDR
NOK
PLN
ZAR
AED
DKK
NIS
ILS
CLP
EGP
VEF
VND
NZD
CZK
COP
DZD
ARS

Complete the "embed" feature

The idea is to embed a story related to a specific query.
Here the result of an embed:

capture decran 2013-10-14 a 15 48 36

1/ Add a link "share" in a a story in the scale visualisation
(like below but without the grey background, on the link in red)

capture decran 2013-10-14 a 15 54 53

2/ On click on the link, open the same information as in the card visu (using a pop-up info ?)
capture decran 2013-10-14 a 15 55 22

3/The generated code should generated the embed code with the result above (same result in the scale or car visu)

Cards visualisation integration: some optimisations

  • Click on "more infos" : The cursors appears like a "text cursor", it should be a pointer
  • As it's difficult to reduce the height of the cards, why don"t integrate the icon of one of a Storie's theme under the title?

Implement the "filter" feature

For the 2 visualisation, add the ability to filter the results by:

tags (country,currency,theme)

type (top stories/all the stories)

Complete the install note with the "how to change the design" part

The idea is to answer to these questions:

  • What parts of the app are designed with extension and modification in mind?
    • How is the design of the app specified?
      • How robust is the "stylesheet"? Can you tamper with it without breaking the app?
    • How are the views of individual "stories" (database items) generated?
    • What are the templates for the various pages of the app like? How much can you change in them?

Optimize stories placements and position

We could optimize the display of the stories along the scale, before place it on a new line, we could check before if the story has space to be displayed on an existing line

Cards visualisation: separate the relevant stories from others

Currently we don't know if a story is "relevant" (relevant grade > 5) or not.

It would be better if we separate the cards in two parts:

Most relevant results (title of the bloc)
List of cards with a grade from 10 to 6

Other results(title of the bloc)
List of cards with a grade from 0 to 6

Complete the "share" feature

On scale visu

When I click on share, the url link to share should be the same as the link for my query+the comparison feature.

For example, If my query is "48.0 billion British pounds" and I want to share the story "Public Debt Interest in 2011", the link to share should be:

http://okf-spendingstories-staging.herokuapp.com/#/search/?q=48000000000&c=GBP&visualization=scale&title=Public%20Debt%20Interest%20in%202011

On Card visu

When I click on share, the url link to share should be the same as the link for my query+the comparison feature.

For example, If my query is "48.0 billion British pounds" and I want to share the story "Public Debt Interest in 2011", the link to share should be:

http://okf-spendingstories-staging.herokuapp.com/#/search/?q=48000000000&c=GBP&visualization=cards&title=Public%20Debt%20Interest%20in%202011

The combination of many filters should be a "OR"

The combination of many filters should be a "OR" (instead of a "AND").

For example, if I choose the filters "country>france" and "themes>books", I should see the stories related to france or books.

Comparison feature: remove the navigation arrows

When I'm on one specifi story (using the comparison feature, or the share), the navigation arrow are still there but don't work.

We should remove them because there is no story before or after

capture decran 2013-10-21 a 14 28 47

Simplifiy the wording for equivalences

Général:
Write in the query:

"Your query for 190,000 US dollars represents"

CARD VISU
Write above the cards

(XXXX US dollars) represents ≈ (XX%) of
(Title of the card)

SCALE VISU
Write above the cards

≈ (equivalence) of
(Title of the card)

filters: fermeture de la select-list lors d'une action du user

  • Quand une select-list de filtres est ouverte et que j'appuis sur "retour" sur mon clavier (backspace) ça fait un retour navigateur et la select-list reste ouverte.
    C'est un comportement plutôt normal mais je trouve ça perturbant, est ce qu'on ne pourrait pas faire en sorte que toute mauvaise touche ferme juste la select-list?
    capture decran 2013-09-05 a 17 01 53

understand user's query: humanize the result

Currently if I type 2 millions, the suggested result is "2000000".
capture decran 2013-10-10 a 21 38 03

But after typing enter, I can see "Your query for 200.0 million" in a human format.
capture decran 2013-10-10 a 21 39 30

Can we display the human format in the suggested results?

Important: We also need to think about the translation is the library used for humanize is easily forkable and translatable?

Clean dependencies and installed apps

I think there is some inconsistencies between requirements_core.txt and the actual dependencies. For instance, you added djangular in the INSTALLED_APPS (I don't know if you use it) but it's not in requirements_core.txt .
But there is django-angular==0.1.4 (an other application different than djangular which seems never used).

Please take a look and don't forget to add system dependencies in the README.md file. (You added pyquery without specify libxml2 and libxslt, removed now)

Fix Not a Number issue on search interface

What is this bug

When you go directly to the search interface without entering a query amount you will get NaN errors on the view.
image
image

How to reproduce this bug:

  • go directly to the search interface at http://<your local server>/#/search/

Scale visu > one story : write the % equivalence beetween the query and the story

Il faudrait afficher " is roughly equivalent to x% of"

Calcul :
(amount queried / amount of the story)*100

Si resultat<1, arrondir au centieme, 2chiffres après la virgule (ex : 0,12%)
Sinon, arrondir à L'entier (ex: 12%)

Il faudrait ajouter 2 conditions:
Si larrondi a l'entier =100 marquer "is roughly the equivalent of"
Si l'arrondi au centième = 0.00 ne rien marquer pour l'instant ( tu as une idée ?)
Si l'arrondi a l'entier >100, ne rien marquer pour l'instant ( tu as une idée ? Peut être "est x fois le montant de )

C'est vraiment pour le,proto, on devra se pencher plus en détails sur un affichage qui parait etre ecrit par un humain du genre "plus de 3 fois" "presque 10 fois" etc :)

Card visualisation & comparison feature: need to be plugged

If I'm on the card visualisation, I can see the most relevant results.

But in the box "compare", the non relevant example are proposed. Is it possible to filter this list in order to suggest only the relevant stories?
Otherwise the user is very disappointed to have no results.

Document the API

Every API endpoint should be documented to know:

  • what this endpoint returns (describe the data)
  • what we can do with this endpoint (describe the operation on data)
  • how the result can be filtered

Wording : some points to fix

Wording "your query"
Mettre dollars, euros et pounds avec un "s" à la fin:
ex: Your query for 5.7 million dollarS
capture decran 2013-08-22 a 18 27 39

Wording "euro" for "your query"
Replace "Your query for 5.7 million EU euro" by "Your query for 5.7 million Euros"
(remove EU and write Euros with an uppecase for the E).
capture decran 2013-08-22 a 18 28 10

Wording "equivalence"

  • In the yellow tag (original amount) : use the full name of the currency instead of the code ISO
    Ex : "Cost: 4.5 million British pounds in 2008" instead of "Cost: 4.0 million GBP in 2008"
    And with a "s" !
  • In the equivalence : add the "s" at the end of euros, pounds, dollars

Contribution form > step 2

  • use the full name of the currency instead of the code ISO
    Ex: Write "123,344.00 Belize dollars is..." instead of "BZD123,344.00 is ..."

[Cards] No stories visible when filter is added

On card visualization, if you add a filter (ex: a theme) and there is no such relevant stories the card viz shows nothing but "load more".
image

We should have:

  • One description saying that no relevant stories have been found
  • AND/OR all cards are loaded

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.