<commit_before>#!/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.

"""Statistic (Model) query functions.
"""

__authors__ = [
    '"<NAME>" <<EMAIL>>',
  ]


import calendar

from datetime import date
from datetime import datetime
from datetime import timedelta
from django.utils import simplejson
from gviz import gviz_api

from soc.logic.models import base

from soc.modules.gsoc.logic.models import program as program_logic
from soc.modules.gsoc.logic.models import student_proposal as \
    gsoc_proposal_logic
from soc.modules.gsoc.logic.models import student_project as \
    gsoc_project_logic

import soc.models.countries
import soc.models.student as student_model
import soc.modules.statistic.logic.instr_to_obj_mapper
import soc.modules.statistic.models.statistic


class Error(Exception):
  """Base class for all exceptions raised by this module.
  """

  pass


class ProtocolError(Error):
  """Class which concerns protocol errors.
  """

  pass

class Logic(base.Logic):
  """Logic methods for the statistic model
  """

  ACCESS_TYPES = ['org_admin', 'host']

  BATCH_SIZE = 10

  def __init__(self, model=soc.modules.statistic.models.statistic.Statistic,
               base_model=None, scope_logic=program_logic):
    """Defines the name, key_name and model for this entity.
    """

    self.helper = soc.modules.statistic.logic.instr_to_obj_mapper.Mapper(self)

    super(Logic, self).__init__(model=model, base_model=base_model,
        scope_logic=program_logic)


  def collectDispatcher(self, statistic):
    """Chooses a function for statistic collection depending on the its type.
    """

    instructions = simplejson.loads(statistic.instructions_json)
    type = instructions.get('type')

    if type == 'per_field':
      return self._preparePerField(statistic, instructions)
    elif type == 'overall':
      return self._prepareOverall(statistic, instructions)
    elif type == 'average':
      return self._prepareAverage(statistic, instructions)

  def clearStatistic(self, statistic):
    """Clears all data for a given statistic.<commit_msg>BATCH SIZE increased to 100.<commit_after>#!/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.

"""Statistic (Model) query functions.
"""

__authors__ = [
    '"<NAME>" <<EMAIL>>',
  ]


import calendar

from datetime import date
from datetime import datetime
from datetime import timedelta
from django.utils import simplejson
from gviz import gviz_api

from soc.logic.models import base

from soc.modules.gsoc.logic.models import program as program_logic
from soc.modules.gsoc.logic.models import student_proposal as \
    gsoc_proposal_logic
from soc.modules.gsoc.logic.models import student_project as \
    gsoc_project_logic

import soc.models.countries
import soc.models.student as student_model
import soc.modules.statistic.logic.instr_to_obj_mapper
import soc.modules.statistic.models.statistic


class Error(Exception):
  """Base class for all exceptions raised by this module.
  """

  pass


class ProtocolError(Error):
  """Class which concerns protocol errors.
  """

  pass

class Logic(base.Logic):
  """Logic methods for the statistic model
  """

  ACCESS_TYPES = ['org_admin', 'host']

  BATCH_SIZE = 100

  def __init__(self, model=soc.modules.statistic.models.statistic.Statistic,
               base_model=None, scope_logic=program_logic):
    """Defines the name, key_name and model for this entity.
    """

    self.helper = soc.modules.statistic.logic.instr_to_obj_mapper.Mapper(self)

    super(Logic, self).__init__(model=model, base_model=base_model,
        scope_logic=program_logic)


  def collectDispatcher(self, statistic):
    """Chooses a function for statistic collection depending on the its type.
    """

    instructions = simplejson.loads(statistic.instructions_json)
    type = instructions.get('type')

    if type == 'per_field':
      return self._preparePerField(statistic, instructions)
    elif type == 'overall':
      return self._prepareOverall(statistic, instructions)
    elif type == 'average':
      return self._prepareAverage(statistic, instructions)

  def clearStatistic(self, statistic):
    """Clears all data for a given statistic.
{'fraction_non_alphanumeric': 0.09040940106141016, 'fraction_numerical': 0.00530705079605762, 'mean_word_length': 4.2144268774703555, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6433958', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1476, 'n_words': 491}