Пример #1
0
    def setUp(self):
        DenunciationCategory.objects.create(name='Racismo', gravity='High')
        DenunciationCategory.objects.create(name='Plágio', gravity='Medium')
        self.adm = DomainAdministrator.objects.create(id=1, username='******')
        self.dom = Domain()
        self.dom.application_name = "www.test.com"
        self.dom.administrator = self.adm
        self.dom.save()

        self.adm2 = DomainAdministrator.objects.create(id=2, username='******')
        self.dom2 = Domain()
        self.dom2.application_name = "www.test2.com"
        self.dom2.administrator = self.adm2
        self.dom2.save()
Пример #2
0
def load_datasets():
    print('=' * 80)
    print(
        f'Importing data sets from "{data_base_path}"\ninto {engine.name} database'
    )
    print('=' * 80)
    # Dictionary of table_name : (file_name, separator)
    datasets = {
        'ppi_data': ('PPI_interface_mapped_to_exon.csv', ','),
        'exons_to_domains_data': ('final.csv', ','),
        'gene_info': ('gene_info.csv', ','),
        Gene: ('gene_name2entrez_id.csv', ','),
        Domain: ('Pfam-A.clans.tsv', '\t'),
    }

    # --- Write dataframes to tables in database
    for table_name, data_file in datasets.items():
        print(f'Adding table {table_name}:')
        print(f'\tParsing file "{data_file[0]}"')
        data = pd.read_csv(path.join(data_base_path, data_file[0]),
                           sep=data_file[1])
        print(
            f'\tWriting {data.shape[0]} rows and {data.shape[1]} columns to database'
        )

        # Write to database using Django models
        if type(table_name) is django.db.models.base.ModelBase:
            table_name.objects.all().delete()

            # Gene
            if table_name is Gene:
                for _, row in tqdm(data.iterrows(), total=data.shape[0]):
                    entry = Gene()
                    entry.gene_symbol = row['Gene name']
                    entry.ensembl_id = row['Gene stable ID']
                    entry.save()

            # Domain
            elif table_name is Domain:
                for _, row in tqdm(data.iterrows(), total=data.shape[0]):
                    entry = Domain()
                    entry.pfam_id = row['PfamId']
                    entry.symbol = row['Symbol3']
                    entry.description = row['Description']
                    entry.save()

        # Write to database directly using Pandas to_sql method
        else:
            data.to_sql(table_name, engine, if_exists='replace', index=False)
        print(f'\tDone')
Пример #3
0
    def handle(self, *args, **options):

        # Create domain
        domain = Domain(name='pass.com')
        domain.save()

        # Create owner
        agent = Agent.objects.create_user(email='*****@*****.**',
                                          password='******')
        agent.is_owner = True
        agent.domain = domain
        agent.save()

        # Create salesteam
        for i in range(1, 5):
            agent = Agent.objects.create_user(email='salesman' + str(i) +
                                              '@pass.com',
                                              password='******')
            agent.domain = domain
            agent.save()

        # Create clients
        for _ in range(1, random.randrange(1, 24)):
            client = Client(name=fake.company())
            client.save()

            # Create managers
            for _ in range(1, random.randrange(12)):
                Manager(client=client,
                        first_name=fake.first_name(),
                        last_name=fake.last_name(),
                        title=fake.job(),
                        email=fake.free_email(),
                        phone=fake.phone_number()).save()

        # Create competitors
        for _ in range(1, random.randrange(24)):
            competitor = Competitor(name=fake.company())
            competitor.save()

        # Create opportunities
        for _ in range(1, random.randrange(100)):

            cmp_count = random.randint(6, 12)

            agent = random.choice(Agent.objects.all())
            client = random.choice(Client.objects.all())

            opportunity = Opportunity(
                title = fake.sentence(nb_words=6), \
                agent = agent, \
                client = client, \
                domain = domain, \

                deadline = datetime.datetime.now() + datetime.timedelta(days=random.randrange(100,120)), \
                budget = 60000 + (random.randrange(60)*1000), \
                margin = random.randrange(40)/100, \
                milestone = random.choice(Opportunity.MILESTONES)[0], \

                # Relationship


                rel_knowledge = random.choice([True,False]), \
                
                # Competitors


                cmp_knowledge = random.choice([True,False]), \
                cmp_count = cmp_count, \
                
                # Solution


                sol_leader = random.choice([True,False]), \
                sol_refs = random.choice([True,False]), \
                sol_understanding = random.choice([True,False]), \
                sol_quantify = random.choice([True,False]), \
                sol_create_requirements = random.choice([True,False]), \
                sol_negociation = random.choice([True,False]))

            opportunity.save()

            for _ in range(1, random.randrange(cmp_count)):
                Activity()

            # Create competitors
            for _ in range(1, random.randrange(cmp_count)):

                CompetitorOpportunity(
                    competitor = random.choice(Competitor.objects.all()), \
                    opportunity = opportunity, \
                    appreciation = random.choice(CompetitorOpportunity.APPRECIATION)[0], \
                    relationship = random.choice(CompetitorOpportunity.RELATIONSHIP)[0], \
                    fullfilment = random.choice(CompetitorOpportunity.FULLFILMENT)[0], \
                    pro = fake.sentence(nb_words=26), \
                    cons = fake.sentence(nb_words=26), \
                    notes = fake.sentence(nb_words=26)
                ).save()

            # Create requirements
            for _ in range(1, random.randrange(6)):

                Requirement(
                    description = fake.sentence(nb_words=6), \
                    opportunity = opportunity, \
                    fulfillment = random.choice(Requirement.FULLFILMENT)[0], \
                    notes = fake.sentence(nb_words=16)
                ).save()