#!/usr/bin/python2.5
#
# Copyright 2010 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Starts an interactive shell which allows to create statistic entities.

Usage is simple:

In order to seed all available statistics, just type:
>>> seed_all()

In order to seed one statistic:
>>> seed_one(link_id)
where link_id is for the desired statistic

In order to change program in scope:
>>> set_program(key_name)
where key_name represents a new program

In order to terminate the script:
>>> exit()
"""


import sys
import interactive
interactive.setup()

from django.utils import simplejson

from soc.logic import dicts

from soc.modules.gci.logic.models.program import logic as program_logic

from soc.modules.statistic.logic.models.statistic import logic as \
    statistic_logic

from soc.modules.statistic.models.statistic import Statistic


SUCCESS_MSG_FMT = 'Statistic %s has been sucessfully added.'
FAILURE_MSG_FMT = 'An error occured while adding %s statistic.'
DOES_NOT_EXISTS_MSG_FMT = 'Statistic %s does not exists.'

VISUALIZATION_SETS = {
    "cumulative_standard": [
        "Table",
        "BarChart",
        "ColumnChart",
        "ImageChartBar",
        ],
    "cumulative_countries": [
        "Table"
        ],
    "single_standard": [
        "Table",
        "BarChart",
        "ColumnChart",
        "ImageChartBar",
        "ImageChartP",
        "ImageChartP3",
        "PieChart",
        "ScatterChart"
        ],
      "single_countries": [
          "Table",
          "GeoMap"
          ]
    }

STATISTIC_PROPERTIES = {
    "mentors_per_continent": (
        "Mentors Per Continent",
        {
        "type": "per_field",
        "field": "continent",
        "model": "gci_mentor",
        "subsets": [("all", {}), ("referenced", {}), ("no-referenced", {})],
        "filter": "property_filter",
        "params": {
            "ref_logic": "gci_task",
            "ref_field": "mentors",
            "program_field": "program",
            "property_conditions": {
                "status": ["active", "inactive"]
                 },
            }
        },
        {
        "description": [("continent", "string", "Continent"),
                        ("all_mentors", "number", "Mentors"),
                        ("pro_mentors", "number", "Mentors with tasks"),
                        ("nop_mentors", "number", "Mentors without tasks")],
        "options": {
            'Mentors Per Continent (cumulative)': {
                "visualizations": VISUALIZATION_SETS['cumulative_standard'],
                "columns": [0, 1, 2]
                },
            'Mentors Per Continent (all)': {
                "visualizations": VISUALIZATION_SETS['single_standard'],
                "columns": [0]
                },
            'Mentors Per Continent (with tasks)': {
                "visualizations": VISUALIZATION_SETS['single_standard'],
                "columns": [1]
                },
            'Mentors Per Continent (without tasks)': {
                "visualizations": VISUALIZATION_SETS['single_standard'],
                "columns": [2]
                }
            }
        },
        "org_admin"),
    "students_per_age": (
        "Students Per Age",
        {
        "type": "per_field",
        "field": "age",
        "model": "gci_student",
        "transformer": "remove-out-of-range",
        "filter": "property_filter",
        "params": {
            "program_field": "scope",
            "property_conditions": {
                "status": ['active', 'inactive']
                 },
            }
        },