• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cnr-ibba / SMARTER-database / 9189630163

22 May 2024 10:26AM UTC coverage: 94.311%. Remained the same
9189630163

Pull #121

github

web-flow
Merge 389cf0ae7 into fcdb3ce6a
Pull Request #121: ⬆️ Bump jinja2 from 3.1.2 to 3.1.4

2984 of 3164 relevant lines covered (94.31%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.19
/src/data/add_breed.py
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
"""
1✔
4
Created on Thu Apr  1 12:28:31 2021
5

6
@author: Paolo Cozzi <paolo.cozzi@ibba.cnr.it>
7

8
Add or update a breed in smarter database using CLI
9
"""
10

11
import click
1✔
12
import logging
1✔
13

14
from pathlib import Path
1✔
15

16
from src.features.smarterdb import (
1✔
17
    global_connection, get_or_create_breed, BreedAlias, Dataset)
18

19
logger = logging.getLogger(__name__)
1✔
20

21

22
@click.command()
1✔
23
@click.option(
1✔
24
    '--species_class',
25
    type=click.Choice(
26
        ['Sheep', 'Goat'],
27
        case_sensitive=False),
28
    required=True,
29
    help="The generic species of this breed (Sheep or Goat)")
30
@click.option(
1✔
31
    '--name',
32
    type=str,
33
    required=True,
34
    help="The breed name")
35
@click.option(
1✔
36
    '--code',
37
    type=str,
38
    required=True,
39
    help="The breed code")
40
@click.option(
1✔
41
    '--alias',
42
    type=str,
43
    multiple=True,
44
    help="The FID used as a breed code in genotype file")
45
@click.option(
1✔
46
    '--dataset', type=str, required=True,
47
    help="The raw dataset file name (zip archive)"
48
)
49
def main(species_class, name, code, alias, dataset):
1✔
50
    """Add or update a breed into SMARTER database"""
51

52
    logger.info(f"{Path(__file__).name} started")
1✔
53

54
    # get the dataset object
55
    dataset = Dataset.objects(file=dataset).get()
1✔
56

57
    # fix input parameters
58
    aliases = [BreedAlias(fid=fid, dataset=dataset) for fid in alias]
1✔
59
    species_class = species_class.capitalize()
1✔
60
    code = code.upper()
1✔
61

62
    # get a breed object relying on parameters
63
    breed, modified = get_or_create_breed(
1✔
64
        species_class=species_class, name=name, code=code, aliases=aliases)
65

66
    if modified:
1✔
67
        logger.info(f"{breed} added to database")
1✔
68

69
    logger.info(f"{Path(__file__).name} ended")
1✔
70

71

72
if __name__ == '__main__':
1✔
73
    log_fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
×
74
    logging.basicConfig(level=logging.INFO, format=log_fmt)
×
75

76
    # connect to database
77
    global_connection()
×
78

79
    main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc