Esempio n. 1
0
File: flow.py Progetto: z0x010/eums
class Flow(models.Model):
    class Label(object):
        IMPLEMENTING_PARTNER = 'IMPLEMENTING_PARTNER'
        WEB = 'WEB'
        MIDDLE_MAN = 'MIDDLE_MAN'
        END_USER = '******'

    NO_OPTION = -1

    temp_end_nodes = IntegerArrayField(dimension=2, null=True)
    optional_end_nodes = IntegerArrayField(dimension=2, null=True)
    final_end_nodes = IntegerArrayField(dimension=2, null=True)

    label = models.CharField(max_length=255,
                             choices=((Label.END_USER, 'End User'),
                                      (Label.MIDDLE_MAN, 'Middleman'),
                                      (Label.IMPLEMENTING_PARTNER,
                                       'Implementing Partner'), (Label.WEB,
                                                                 'Web')),
                             unique=True)

    def is_temp_ended(self, answer):
        return_value = self.temp_end_nodes and self._get_rapid_pro_end_node(
            answer) in self.temp_end_nodes
        return return_value

    def is_final_ended(self, answer):
        return_value = self.final_end_nodes and self._get_rapid_pro_end_node(
            answer) in self.final_end_nodes
        return return_value

    def is_optional_ended(self, answer):
        return_value = self.optional_end_nodes and self._get_rapid_pro_end_node(
            answer) in self.optional_end_nodes
        return return_value

    def _get_rapid_pro_end_node(self, answer):
        question_id = answer.question.id
        value_id = answer.value.id if type(
            answer.value) is Option else self.NO_OPTION
        return [question_id, value_id]

    def __unicode__(self):
        return '%s' % str(self.label)

    def question_with(self, **kwargs):
        question = self.questions.filter(**kwargs).first()
        return question.get_subclass_instance()
Esempio n. 2
0
class ConsigneeItem(models.Model):
    consignee = models.ForeignKey('Consignee')
    item = models.ForeignKey('Item')
    amount_received = models.BigIntegerField(default=0)
    deliveries = IntegerArrayField(dimension=1)

    class Meta:
        unique_together = ('consignee', 'item')

    def latest_delivery(self):
        pass

    def save(self, **kwargs):
        super(ConsigneeItem, self).save(**kwargs)
        if not len(self.deliveries):
            self.delete()
        return self

    def available_balance(self):
        from eums.models.distribution_plan_node import DistributionPlanNode
        deliveries = DistributionPlanNode.objects.filter(
            pk__in=self.deliveries, consignee=self.consignee)
        total_amount_lost = reduce(
            lambda total, delivery: total + delivery.total_amount_lost(),
            deliveries, 0)
        amount_distributed = reduce(
            lambda total, delivery: total + delivery.quantity_out(),
            deliveries, 0)
        return self.amount_received - amount_distributed - total_amount_lost
Esempio n. 3
0
class ModuleInstance(models.Model):
    name = models.CharField(max_length=64)

    # The module definition which this instance is part of
    parent = models.ForeignKey(ModuleDefinition, related_name="children")

    # The module definition that specifies the implementation of this instance
    definition = models.ForeignKey(ModuleDefinition, related_name="instances")

    # `nodes` has the same length as ModuleInstance.definition.ports.
    # It is related to the definition such that nodes[i] is the node ID (within parent)
    # of the input or output port specified by definition.ports[i]
    nodes = IntegerArrayField()

    # Position within the parent definition
    posX = models.FloatField()
    posY = models.FloatField()
    posWidth = models.FloatField()
    posHeight = models.FloatField()

    def dict(self):
        return {
            "name": self.name,
            "parent": self.parent.id,
            "definition": self.definition.id,
            "nodes": self.nodes,
            "posX": self.posX,
            "posY": self.posY,
            "posWidth": self.posWidth,
            "posHeight": self.posHeight
        }
Esempio n. 4
0
class Wire(models.Model):
    name = models.CharField(max_length=32)

    # The module definition which this wire is part of
    parent = models.ForeignKey(ModuleDefinition)

    # The node that drives this wire
    node_in = models.PositiveIntegerField()

    # The node this wire drives
    node_out = models.PositiveIntegerField()

    # The number of bits carried by this wire
    width = models.PositiveIntegerField()

    # If this wire outputs to more than one node (must be inputs to wires),
    # this array contains the node numbers that it splits OR copies to.
    # If the widths of the connecting wires add up to the length of this wire,
    # it is considered a split and bits will be sent in the order specified here.
    # If the width of each wire are equal to this wire's width, it is a copy.
    # Otherwise, it is considered a split. Extra bits are discarded (causes warning)
    # and insufficient bits are wired `undefined` (also causes warning.)
    split_copy_nodes = IntegerArrayField()
    combine_nodes = IntegerArrayField()

    # Position within the parent definition
    in_posX = models.FloatField()
    in_posY = models.FloatField()
    out_posX = models.FloatField()
    out_posY = models.FloatField()

    def dict(self):
        return {
            "name": self.name,
            "parent": self.parent.id,
            "node_in": self.node_in,
            "node_out": self.node_out,
            "width": self.width,
            "split_copy_nodes": self.split_copy_nodes,
            "combine_nodes": self.combine_nodes,
            "posX": self.posX,
            "posY": self.posY
        }
Esempio n. 5
0
class GQModule(models.Model):
    species = models.CharField(u'Species', max_length=SPECIES_MAX_LENGTH, blank=False, choices=SPECIES_CHOICES)

    full_name = models.CharField(u'Module',
                                 max_length=MODULE_NAME_MAX_LENGTH,
                                 primary_key=True,
                                 blank=False,
                                 help_text=escape(
                                     u'Module name specified as <series name>_<platform name>#<module number>'))

    entrez_ids = IntegerArrayField(verbose_name="Entrez IDs", dimension=1, blank=False,
                                   help_text=u'Entrez IDs of genes contained in this module. '
                                             u'Should be separated by comma.')

    def split_full_name(self):
        """
        :rtype: str, str, int
        """
        gse_gpl, module_number = self.full_name.split('#')
        gse, gpl = gse_gpl.split('_')
        return gse, gpl, int(module_number)

    @staticmethod
    def merge_full_name(gse, gpl, module_number):
        """
        Create full module name like GSE_GPL#module_number
        :type module_number: int
        :type gpl: str
        :type gse: str
        :rtype str
        """
        return '{}_{}#{}'.format(gse, gpl, module_number)

    class Meta:
        verbose_name = 'Module'
        verbose_name_plural = 'Modules'
        db_table = 'modules'
        unique_together = (('species', 'full_name'),)

    def __unicode__(self):
        id_module = self.full_name.split('#')
        series_platform = id_module[0].split('_')
        return u'series {} platform {} module {} ({})'.format(
            series_platform[0], series_platform[1], id_module[1], self.species)
Esempio n. 6
0
class IntModel(models.Model):
    field = IntegerArrayField()
    field2 = IntegerArrayField(dimension=2)
Esempio n. 7
0
class AppStoreAppInfo(APIModel):
    create_time = models.DateTimeField(auto_now_add=True)

    app = models.ForeignKey(AppStoreApp,
                            related_name='+',
                            db_index=False,
                            on_delete=models.DO_NOTHING)

    data = hstore_field.HStoreField()

    itunes_id = data.long_property()
    bundle_id = data.string_property()

    mac_software = data.bool_property()

    name = data.string_property()
    description = data.string_property()
    release_notes = data.string_property()

    version = data.string_property()

    icon_60 = data.string_property()
    icon_100 = data.string_property()
    icon_512 = data.string_property()

    category = data.int_property()

    price = data.float_property()
    currency = data.string_property()

    size_bytes = data.long_property()

    rating = data.float_property()
    reviews_count = data.int_property()

    current_version_rating = data.float_property()
    current_version_reviews_count = data.int_property()

    content_rating = data.string_property()  # 4+, etc.

    developer_id = data.long_property()
    developer_url = data.string_property()
    developer_name = data.string_property()

    categories = IntegerArrayField()
    screenshots = TextArrayField()
    ipad_screenshots = TextArrayField(null=True)

    release_date = models.DateTimeField()

    country = models.CharField(null=True, max_length=2)

    @property
    def short_name(self):
        return text.app_short_name(self.name)

    def to_tiny_dict(self):
        return {
            'iTunesId': self.itunes_id,
            'name': self.name,
            'icon': {
                'small': self.icon_60,
            },
            'developer': {
                'id': self.developer_id,
                'name': self.developer_name,
            },
        }

    def to_dict(self):
        full_dict = self.to_tiny_dict()

        full_dict['bundleId'] = self.bundle_id

        full_dict['version'] = self.version
        full_dict['category'] = self.category
        full_dict['description'] = self.description
        full_dict['icon']['medium'] = self.icon_100
        full_dict['icon']['large'] = self.icon_512

        full_dict['developer']['url'] = self.developer_url

        full_dict['rating'] = self.rating
        full_dict['reviewCount'] = self.reviews_count
        full_dict['currentRating'] = self.current_version_rating
        full_dict['currentRatingStars'] = ''.join(
            [u'★'] * int(self.current_version_rating))
        full_dict['currentReviewCount'] = self.current_version_reviews_count

        full_dict['screenshots'] = self.screenshots

        return full_dict
Esempio n. 8
0
class ClusterCreationParams(models.Model):
    """
    Definition of  ClusterChoices model for retrieving cluster creation
    parameters from okeanos. Imported djorm_pgarray package
    is needed for custom Arrayfields.
    """
    id = models.IntegerField("Id",
                             primary_key=True,
                             null=False,
                             help_text="Id needed by ember.js store")
    user_id = models.ForeignKey(UserInfo, null=False, help_text="User ID")
    # Project name
    project_name = models.CharField("Project Name",
                                    max_length=255,
                                    null=True,
                                    help_text="Project name from"
                                    " which resources will be requested")
    # Maximum allowed vms
    vms_max = models.IntegerField("Max Vms",
                                  null=True,
                                  help_text="Maximum Allowed Virtual"
                                  " machines")
    # Available vms for user
    vms_av = IntegerArrayField()  # ArrayField
    # Maximum allowed cpus
    cpu_max = models.IntegerField("Max Cpus",
                                  null=True,
                                  help_text="Maximum Allowed Cpus")
    # Available cpus
    cpu_av = models.IntegerField("Available Cpus",
                                 null=True,
                                 help_text="Available Cpus")
    # Maximum allowed ram
    ram_max = models.IntegerField("Max Ram",
                                  null=True,
                                  help_text="Maximum Allowed Ram")
    # Available ram
    ram_av = models.IntegerField("Available Ram",
                                 null=True,
                                 help_text="Available Ram")
    # Maximum allowed disk size
    disk_max = models.IntegerField("Max disk size",
                                   null=True,
                                   help_text="Max disk size")
    # Available disk size
    disk_av = models.IntegerField("Available disk size",
                                  null=True,
                                  help_text="Available disk size")
    # network
    net_av = models.IntegerField("Available Networks",
                                 null=True,
                                 help_text="Available Networks")
    # floating ips
    floatip_av = models.IntegerField("Available floating IPs",
                                     null=True,
                                     help_text="Available floating IPs")
    # Cpu choices
    cpu_choices = IntegerArrayField()  # ArrayField
    # Ram choices
    ram_choices = IntegerArrayField()  # ArrayField
    # Disk size choices
    disk_choices = IntegerArrayField()  # ArrayField
    # Disk template choices
    disk_template = TextArrayField()  # ArrayField
    # Operating system choices
    os_choices = TextArrayField()  # ArrayField
    #ssh keys
    ssh_keys_names = TextArrayField()  # ArrayField
    pending_status = models.NullBooleanField(default=False)

    class Meta:
        verbose_name = "Cluster"
        app_label = 'backend'
Esempio n. 9
0
class DeleteRecords(models.Model):
    nodes_to_delete = IntegerArrayField(dimension=1)
    nodes_with_deleted_dependencies = IntegerArrayField(dimension=1)
Esempio n. 10
0
class Route(models.Model):
    stop_ids = IntegerArrayField(db_index=True, unique=True)

    def is_to_north(self):
        import services

        first_stop = services.get_stop(self.stop_ids[0])
        last_stop = services.get_stop(self.stop_ids[-1])
        return first_stop['latlon'][0] < last_stop['latlon'][0]

    def get_parent(self):
        return None

    def get_short_name(self):
        import services

        return '%s %s: %s %s %s' % (_('Route'),
                                    self.id,
                                    services.get_heb_stop_name(self.stop_ids[0]),
                                    '&#8604;',
                                    services.get_heb_stop_name(self.stop_ids[-1]))

    def print_nice(self):
        import services

        for idx, stop_id in enumerate(self.stop_ids):
            print '%2d %s' % (idx, services.get_stop_name(stop_id))


    def get_services(self):
        return self.service_set.all().order_by('id')

    def group_into_services(self):
        from itertools import groupby

        trips = self.trip_set.filter(valid=True)
        group_it = groupby(trips, key=lambda t: t.get_exp_time_strings())
        for k, trips_it in group_it:
            s = Service.objects.get_or_create(route=self,
                                              local_time_str=k
            )[0]
            s.trips.add(*list(trips_it))


    def get_stops(self):
        import services

        return services.get_stops(self.stop_ids)

    def first_stop_id(self):
        return self.stop_ids[0]

    def last_stop_id(self):
        return self.stop_ids[-1]

    def admin_unicode(self):
        import services

        first_stop_name = services.get_heb_stop_name(self.stop_ids[0])
        last_stop_name = services.get_heb_stop_name(self.stop_ids[-1])

        result = '%s: %s stops from %s to %s' % (self.id,
                                                 len(self.stop_ids),
                                                 first_stop_name,
                                                 last_stop_name,
        )
        return unicode(result)