<commit_before>import logging
logger = logging.getLogger("webapi")

import socorro.database.database as db
import socorro.webapi.webapiService as webapi
import socorro.lib.util as util
import socorro.lib.datetimeutil as dtutil

import collections as col
import functools as ft

from collections import defaultdict

class CurrentVersions(webapi.JsonServiceBase):
  def __init__(self, configContext):
    super(CurrentVersions, self).__init__(configContext)
    logger.debug('CurrentVersions __init__')

  # curl 'http://localhost:8085/201106/current/versions'
  uri = '/201106/current/versions'

  def get(self, *args):
    connection = self.database.connection()
    cursor = connection.cursor()

    # use the last date that we have data for as the end
    currentVersions = """
                      /* socorro.services.CurrentVersions curentVersions */
                     SELECT product_name, version_string
                     FROM product_selector"""

    cursor.execute(currentVersions)

    defaultdict_factory_with_list = ft.partial(col.defaultdict, list)

    result = col.defaultdict(defaultdict_factory_with_list)
    for product, version in cursor.fetchall():
      result[product]['version'].append(version)

    return {'currentversions': result}<commit_msg>bug 676612 - adjust for new product_info view, and allow optional arg to return only featured versions<commit_after>import logging
logger = logging.getLogger("webapi")

import socorro.database.database as db
import socorro.webapi.webapiService as webapi
import socorro.lib.util as util
import socorro.lib.datetimeutil as dtutil

import collections as col
import functools as ft

from collections import defaultdict

class CurrentVersions(webapi.JsonServiceBase):
  def __init__(self, configContext):
    super(CurrentVersions, self).__init__(configContext)
    logger.debug('CurrentVersions __init__')

  # curl 'http://localhost:8085/201106/current/versions'
  uri = '/201106/current/versions/(.*)'

  def get(self, *args):

    connection = self.database.connection()
    cursor = connection.cursor()

    featured_only = False
    if 'featured' in args:
      featured_only = True

    # use the last date that we have data for as the end
    currentVersions = """
                      /* socorro.services.CurrentVersions curentVersions */
                     SELECT product_name, version_string, is_featured,
                            start_date, end_date
                     FROM product_info"""

    if featured_only:
      currentVersions += """ WHERE is_featured"""

    cursor.execute(currentVersions)

    defaultdict_factory_with_list = ft.partial(col.defaultdict, list)

    result = col.defaultdict(defaultdict_factory_with_list)
    for product, version, featured, start, end in cursor.fetchall():
      releases = { 'version': version,
                   'start_date': str(start),
                   'end_date': str(end) }

      if not featured_only:
        releases['featured'] = featured

      result[product]['releases'].append(releases)

    return {'currentversions': result}
{'fraction_non_alphanumeric': 0.08999350227420402, 'fraction_numerical': 0.012345679012345678, 'mean_word_length': 3.386039886039886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6522060', 'n_tokens_mistral': 886, 'n_tokens_neox': 820, 'n_words': 219}