Exemplo n.º 1
0
class ReportCard(models.Model):
    date = models.DateTimeField(verbose_name='Date Generated')

    active_customers = models.IntegerField('Number of Active Customers',
                                           null=False,
                                           blank=False)
    orders = models.IntegerField('Number of orders', null=False, blank=False)
    churn = models.IntegerField('Number of people who churn',
                                null=False,
                                blank=False)
    new_signups = models.IntegerField('Number of new signups',
                                      null=False,
                                      blank=False)
    expected_demand = models.FloatField('Expected Demand',
                                        default=float(Decimal('0.00')))
    demand_actualising = models.FloatField('Probability of demand actualising',
                                           default=float(Decimal('0.00')))
    deviation = models.FloatField('Deviation from recommendation',
                                  default=float(Decimal('0.00')))

    actions = hstore.SerializedDictionaryField(default={})

    percentage_changes = hstore.SerializedDictionaryField(default={})

    objects = hstore.HStoreManager()
Exemplo n.º 2
0
class CustomerCluster(models.Model):
    cluster_number = models.IntegerField('Cluster Number',
                                         null=False,
                                         blank=False,
                                         unique=True)
    cluster_name = models.CharField("Cluster Name",
                                    max_length=255,
                                    null=False,
                                    blank=False)
    cluster_description = models.CharField("Cluster Description",
                                           max_length=255,
                                           null=False,
                                           blank=False)
    mean_orders = models.DecimalField('Mean Number of Orders',
                                      max_digits=6,
                                      decimal_places=2,
                                      default=Decimal('0.00'))
    mean_ratio_amount_time = models.DecimalField(
        'Mean Ratio of Amount Spent against Time',
        max_digits=6,
        decimal_places=2,
        default=Decimal('0.00'))
    mean_vouchers_used = models.DecimalField('Mean Number of Vouchers Used',
                                             max_digits=6,
                                             decimal_places=2,
                                             default=Decimal('0.00'))
    mean_interval = models.DecimalField(
        'Mean Interval between orders(in days)',
        max_digits=6,
        decimal_places=2,
        default=Decimal('0.00'))
    mean_total_spending = models.DecimalField('Mean Total Spending',
                                              max_digits=6,
                                              decimal_places=2,
                                              default=Decimal('0.00'))
    mean_one_off_orders = models.DecimalField('Mean Number of One-Off orders',
                                              max_digits=6,
                                              decimal_places=2,
                                              default=Decimal('0.00'))
    cluster_revenue = models.DecimalField(
        'Total revenue earned from customers in cluster',
        max_digits=10,
        decimal_places=2,
        default=Decimal('0.00'))

    customers = hstore.SerializedDictionaryField(default={})
    percentage_brew_methods = hstore.SerializedDictionaryField(default={})

    def __unicode__(self):
        return 'Cluster Number: %s, Cluster Description: %s, Mean Number of Orders: %s, Mean Ratio of Amount Spent against Time: %s, ' \
               'Mean Number of Vouchers Used: %s, Mean Interval between oredrs(in days): %s' % (self.cluster_number, self.cluster_description, self.mean_orders,
                                                                                                self.mean_ratio_amount_time, self.mean_vouchers_used, self.mean_interval)
Exemplo n.º 3
0
class Document(models.Model):
    document_slug = models.SlugField(null=True, max_length=127)
    document_title = models.TextField(blank=True, null=True)
    document_collection = models.ForeignKey(Document_Collection, null=True)
    document_summary = models.TextField(
        blank=True,
        null=True,
        help_text="This is the first parage of the first page, be default")
    page_count = models.IntegerField(null=True)
    thumbnail = models.TextField(blank=True,
                                 null=True,
                                 help_text="url for image thumbnail")

    metadata = hstore.SerializedDictionaryField(
        null=True, help_text="Document metadata, as a dict")
    objects = hstore.HStoreManager()

    ## need to add: number_of_pages -- makes has_next stuff easier for pages

    def __unicode__(self):
        return "%s" % (self.document_slug)

    def get_absolute_url(self):
        return "/documents/collection/%s/%s/" % (
            self.document_collection.collection_slug, self.document_slug)
Exemplo n.º 4
0
class forms(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL)
    data = hstore.SerializedDictionaryField()

    objects = hstore.HStoreManager()

    def get_absolute_url(self):
        return reverse('form_detail', kwargs={"pk": str(self.id)})
Exemplo n.º 5
0
class WebhookTransaction(models.Model):
    UNPROCESSED = 1
    PROCESSED = 2
    ERROR = 3

    STATUSES = (
        (UNPROCESSED, 'Unprocessed'),
        (PROCESSED, 'Processed'),
        (ERROR, 'Error'),
    )

    date_generated = models.DateTimeField()
    date_received = models.DateTimeField(default=timezone.now)
    body = hstore.SerializedDictionaryField()
    request_meta = hstore.SerializedDictionaryField()
    status = models.CharField(max_length=250,
                              choices=STATUSES,
                              default=UNPROCESSED)

    objects = hstore.HStoreManager()

    def __unicode__(self):
        return u'{0}'.format(self.date_event_generated)
Exemplo n.º 6
0
class Category(models.Model):
    name = models.CharField(verbose_name="名称", max_length=100)
    data = hstore.SerializedDictionaryField(blank=True, verbose_name="数据")
    created = models.DateTimeField(verbose_name='创建时间', default=timezone.now)
    updated = models.DateTimeField(verbose_name='更新时间', auto_now=True)
    operator = models.CharField(max_length=50, verbose_name='操作员', blank=True)
    objects = hstore.HStoreManager()

    def __str__(self):
        return "分类:{}".format(self.name)

    class Meta:
        verbose_name = "分类"
        verbose_name_plural = verbose_name
Exemplo n.º 7
0
class Anuncio(Model):
    id_anuncio = IntegerField()
    year = IntegerField()
    borme = ForeignKey('Borme')
    company = ForeignKey('Company')
    datos_registrales = CharField(max_length=70)
    actos = hstore.SerializedDictionaryField()  # TODO: schema={...}  # TODO: Actos repetidos

    class Meta:
        index_together = ['id_anuncio', 'year']

    #objects = hstore.HStoreManager()

    def get_absolute_url(self):
        return reverse('borme-anuncio', args=[str(self.year), str(self.id_anuncio)])

    def __str__(self):
        return '%d - %d (%d actos)' % (self.id_anuncio, self.year, len(self.actos.keys()))
Exemplo n.º 8
0
class InstagramPost(models.Model):
    url = models.URLField(max_length=256)
    data = hstore.SerializedDictionaryField(blank=True, editable=False)

    def save(self, *args, **kwargs):
        if self._state.adding:
            self.data = self.fetch_post_data()
            print 'self.data:::', self.data
            if not self.data:
                raise ValueError('Cannot be saved, try again or '
                                 'ask your developer to check it out')
        super(InstagramPost, self).save(*args, **kwargs)

    def __unicode__(self):
        return self.url

    def fetch_post_data(self):
        resp = self._fetch_data('https://api.instagram.com/oembed/?url=%s' %
                                self.url)
        if not resp:
            raise ValueError('Cannot get the post data, try again later')
        author_name = resp['author_name']
        caption = resp.get('title')
        return {
            'author_name':
            author_name,
            'author_avatar':
            self._fetch_author_avatar(author_name),
            'author_url':
            resp['author_url'],
            'image_url':
            self._get_image_url(author_name, caption),
            'text':
            resp['title'],
            'created_time':
            re.findall(r'datetime=\"([\dT:+-]+)\"', resp['html'])[0],
        }

    def _fetch_author_avatar(self, username):
        author_media = self._fetch_data(
            "https://www.instagram.com/{username}/?__a=1".format(
                username=username))
        avatar_url = "https://instagramstatic-a.akamaihd.net/null.jpg"
        if author_media:
            avatar_url = author_media['user']['profile_pic_url']

        return avatar_url

    def _get_image_url(self, username, caption):
        author_media = self._fetch_data(
            "https://www.instagram.com/{username}/?__a=1".format(
                username=username))
        image_url = "https://instagramstatic-a.akamaihd.net/null.jpg"
        if author_media:
            for node in author_media['user']['media']['nodes']:
                if node.get('caption') == caption:
                    image_url = node['thumbnail_src']
                    break
        return image_url

    def _fetch_data(self, url):
        try:
            resp = urllib2.urlopen(url)
            data = json.loads(resp.read())
            resp.close()
        except Exception:
            logger.error('Fetch social data. url: %s', url, exc_info=True)
            data = {}
        return data
Exemplo n.º 9
0
class SerializedDataBagNoID(HStoreModel):
    slug = models.SlugField(primary_key=True)
    name = models.CharField(max_length=32)
    data = hstore.SerializedDictionaryField()
Exemplo n.º 10
0
class SerializedDataBag(HStoreModel):
    name = models.CharField(max_length=32)
    data = hstore.SerializedDictionaryField()