Esempio n. 1
0
    def test_unique_two_delete_not_found(self):

        # Delete the zip code from an existing address that doesn't have a zip code.

        p = Pump("data/org_def.json")
        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n765319', u'zip': u'None'}}
        [add, sub] = p.update()
        self.assertTrue(len(add) == 0 and len(sub) == 0)
Esempio n. 2
0
 def test_unique_one_delete(self):
     from rdflib import URIRef, Literal, XSD
     p = Pump()
     p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n111669', u'abbreviation': u'None'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 0 and len(sub) == 1 and (URIRef("http://vivo.ufl.edu/individual/n111669"),
                                              URIRef("http://vivoweb.org/ontology/core#abbreviation"),
                                              Literal("JWRU", datatype=XSD.string)) in sub)
Esempio n. 3
0
 def test_without_lang(self):
     from rdflib import URIRef, Literal
     p = Pump("data/org_def.json", verbose=True)
     p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n928712', u'name': u'Ad ver tising'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 1 and len(sub) == 1 and (URIRef("http://vivo.ufl.edu/individual/n928712"),
                                              URIRef("http://www.w3.org/2000/01/rdf-schema#label"),
                                              Literal("Ad ver tising")) in add)
Esempio n. 4
0
 def test_unique_one_add(self):
     from rdflib import URIRef, Literal
     p = Pump()
     p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n1001011525', u'abbreviation': u'PH9'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 1 and len(sub) == 0 and (URIRef("http://vivo.ufl.edu/individual/n1001011525"),
                                              URIRef("http://vivoweb.org/ontology/core#abbreviation"),
                                              Literal("PH9")) in add)
Esempio n. 5
0
 def test_with_lang(self):
     from rdflib import URIRef, Literal
     p = Pump("data/building_def.json", verbose=True)
     p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n1001011525', u'name': u'Building 42'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 1 and len(sub) == 1 and (URIRef("http://vivo.ufl.edu/individual/n1001011525"),
                                              URIRef("http://www.w3.org/2000/01/rdf-schema#label"),
                                              Literal("Building 42", lang="en-US")) in add)
Esempio n. 6
0
 def test_without_datatype(self):
     from rdflib import URIRef, Literal
     p = Pump("data/building_def.json", verbose=True)
     p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n1001011525', u'url': u'http://a'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 4 and len(sub) == 0 and (None,
                                              URIRef("http://vivoweb.org/ontology/core#linkURI"),
                                              Literal("http://a")) in add)
Esempio n. 7
0
    def test_multiple_one_change_nothing(self):

        #  Do nothing if the multiple values specified match those in VIVO

        p = Pump("data/person_def.json", verbose=True)
        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n1723097935',
                               u'types': u'person;thing;agent;fac;uf;ufc'}}
        [add, sub] = p.update()
        self.assertTrue(len(add) == 0 and len(sub) == 0)
Esempio n. 8
0
 def test_with_datatype(self):
     from rdflib import URIRef, Literal, XSD
     p = Pump("data/building_def.json", verbose=True)
     p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n1001011525', u'abbreviation': u'PH9'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 1 and len(sub) == 0 and (URIRef("http://vivo.ufl.edu/individual/n1001011525"),
                                              URIRef("http://vivoweb.org/ontology/core#abbreviation"),
                                              Literal("PH9", datatype=XSD.string)) in add)
Esempio n. 9
0
    def test_multiple_one_delete(self):

        #  Empty the set of values

        p = Pump("data/person_def.json", verbose=True)
        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n25674',
                               u'research_areas': u'None'}}
        [add, sub] = p.update()
        self.assertTrue(len(add) == 0 and len(sub) == 4)
Esempio n. 10
0
 def test_inject_empty_original_graph(self):
     from rdflib import Graph, URIRef
     p = Pump(verbose=True)
     p.original_graph = Graph()
     p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n8984374104', u'abbreviation': u'None'}}
     [add, sub] = p.update()
     self.assertTrue(
         len(add) == 1 and len(sub) == 0 and (None,
                                              URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
                                              URIRef("http://vivoweb.org/ontology/core#Building")) in add)
Esempio n. 11
0
    def test_unique_three_add_partial_path(self):
        from rdflib import URIRef, Literal
        p = Pump("data/grant_def.json", verbose=True)

        # WARNING.  This test passes by constructing a new datetime interval. Not clear if this is the desired result.

        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n42774', u'start_date': u'2006-03-01'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 5 and len(sub) == 0 and (None,
                                                 URIRef("http://vivoweb.org/ontology/core#dateTime"),
                                                 Literal("2006-03-01")) in add)
Esempio n. 12
0
    def test_unique_three_add_fullpath(self):
        from rdflib import URIRef, Literal
        p = Pump("data/grant_def.json")

        # Add a start date to a grant.  There is no date time interval, so a full path will need to be created

        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n51914', u'start_date': u'2015-03-01'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 5 and len(sub) == 0 and (None,
                                                 URIRef("http://vivoweb.org/ontology/core#dateTime"),
                                                 Literal("2015-03-01")) in add)
Esempio n. 13
0
    def test_unique_two_delete(self):
        from rdflib import URIRef, Literal, XSD

        # Delete the zip code on an existing address

        p = Pump("data/org_def.json")
        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n87597', u'zip': u'None'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 0 and len(sub) == 1 and (URIRef("http://vivo.ufl.edu/individual/n994294"),
                                                 URIRef("http://vivoweb.org/ontology/core#addressPostalCode"),
                                                 Literal("32611", datatype=XSD.string)) in sub)
Esempio n. 14
0
    def test_unique_two_add_to_existing(self):
        from rdflib import URIRef, Literal

        # Add a zip code to the provost's office at UF.  An address already exists, the zip needs to be
        # added to the existing address

        p = Pump("data/org_def.json")
        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n765319', u'zip': u'32653'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 1 and len(sub) == 0 and (URIRef("http://vivo.ufl.edu/individual/n119803"),
                                                 URIRef("http://vivoweb.org/ontology/core#addressPostalCode"),
                                                 Literal("32653")) in add)
Esempio n. 15
0
    def test_unique_two_add_fullpath(self):
        from rdflib import URIRef, Literal
        p = Pump("data/org_def.json")

        # Add a zip code to Lee County Extension Office.  There is no address, so a full path will need
        # to be created

        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n7023301', u'zip': u'32653'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 4 and len(sub) == 0 and (None,
                                                 URIRef("http://vivoweb.org/ontology/core#addressPostalCode"),
                                                 Literal("32653")) in add)
Esempio n. 16
0
    def test_unique_three_delete(self):
        from rdflib import URIRef, Literal, XSD

        # WARNING: Delete start date value from existing datetime interval.  This may not be the desirable data
        # management action

        p = Pump("data/grant_def.json", verbose=True)
        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n650082272', u'start_date': u'None'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 0 and len(sub) == 1 and (None,
                                                 URIRef("http://vivoweb.org/ontology/core#dateTime"),
                                                 Literal("2006-07-01T00:00:00", datatype=XSD.dateTime)) in sub)
Esempio n. 17
0
def main():
    """
    The main function.  Does the work of Simple VIVO
    :return: None
    """
    import sys
    from datetime import datetime
    from vivopump import get_args
    from pump import Pump

    return_code = 0
    print datetime.now(), "Start"
    args = get_args()

    #   Create a Pump and use it to perform the requested actions based on arguments

    p = Pump(args.defn, args.src, args.verbose, args.nofilters, args.inter, args.intra, args.rdfprefix,
             query_parms={'queryuri': args.queryuri,
                          'username': args.username,
                          'password': args.password,
                          'prefix': args.prefix,
                          'uriprefix': args.uriprefix})
    if args.action == 'get':
        n_rows = p.get()
        print datetime.now(), n_rows, "rows in", args.src
    elif args.action == 'update':
        try:
            [add_graph, sub_graph] = p.update()
        except IOError:
            print "File not found"
            return_code = 1
        else:
            add_file = open(args.rdfprefix + '_add.rdf', 'w')
            print >>add_file, add_graph.serialize(format='nt')
            add_file.close()
            sub_file = open(args.rdfprefix + '_sub.rdf', 'w')
            print >>sub_file, sub_graph.serialize(format='nt')
            sub_file.close()
            print datetime.now(), len(add_graph), 'triples to add', len(sub_graph), 'triples to sub'
    elif args.action == 'summarize':
        print p.summarize()
    elif args.action == 'serialize':
        print p.serialize()
    elif args.action == 'test':
        print p.test()
    else:
        print datetime.now(), "Unknown action.  Try sv -h for help"
    print datetime.now(), "Finish"
    sys.exit(return_code)
Esempio n. 18
0
    def test_multiple_one_change(self):
        from rdflib import URIRef

        #  Change the set of values adding one and removing another

        p = Pump("data/person_def.json", verbose=True)
        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n1723097935',
                               u'types': u'person;thing;agent;fac;uf;pd'}}
        [add, sub] = p.update()
        self.assertTrue(len(add) == 1 and len(sub) == 1 and
                        (URIRef("http://vivo.ufl.edu/individual/n1723097935"),
                         URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
                         URIRef("http://vivoweb.org/ontology/core#Postdoc")) in add and
                        (URIRef("http://vivo.ufl.edu/individual/n1723097935"),
                         URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
                         URIRef("http://vivo.ufl.edu/ontology/vivo-ufl/UFCurrentEntity")) in sub)
Esempio n. 19
0
    def test_multiple_one_add(self):
        from rdflib import URIRef

        #  Add multiple values for an attribute to an entity that has no values for the attribute

        p = Pump("data/person_def.json", verbose=True)
        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n1723097935',
                               u'research_areas': u'http://vivo.ufl.edu/individual/n2551317090;http://vivo.ufl.edu/individual/n157098'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 2 and len(sub) == 0 and (URIRef("http://vivo.ufl.edu/individual/n1723097935"),
                                                 URIRef("http://vivoweb.org/ontology/core#hasResearchArea"),
                                                 URIRef("http://vivo.ufl.edu/individual/n2551317090")) in add and
                                                (URIRef("http://vivo.ufl.edu/individual/n1723097935"),
                                                 URIRef("http://vivoweb.org/ontology/core#hasResearchArea"),
                                                 URIRef("http://vivo.ufl.edu/individual/n157098")) in add)
Esempio n. 20
0
    def test_unique_three_change_xsd(self):
        from rdflib import URIRef, Literal, XSD
        p = Pump("data/grant_def.json", verbose=True)

        # WARNING.  This test passes by changing the start date value on an existing datetime interval.  Not sure
        # if this is the desired behavior.

        p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n650082272', u'start_date': u'2006-03-02'}}
        [add, sub] = p.update()
        self.assertTrue(
            len(add) == 1 and len(sub) == 1 and (None,
                                                 URIRef("http://vivoweb.org/ontology/core#dateTime"),
                                                 Literal("2006-03-02")) in add and
                                                (None,
                                                 URIRef("http://vivoweb.org/ontology/core#dateTime"),
                                                 Literal("2006-07-01T00:00:00", datatype=XSD.dateTime)) in sub)
Esempio n. 21
0
 def test_pump_update(self):
     p = Pump("data/building_def.json")
     [add, sub] = p.update("data/buildings.txt")
     self.assertEqual(74, len(add))
     self.assertEqual(76, len(sub))
Esempio n. 22
0
for name, val in program_defaults.items():
    vars(args)[name] = val

if args.verbose:
    print datetime.now(), "Arguments\n", vars(args)

#   Create a Pump and use it to perform the requested actions based on arguments

p = Pump(args.defn, args.src, args.verbose, args.nofilters, query_parms={'query_uri': args.queryuri,
                                                                         'username': args.pwd, 'password': args.pwd},
         uri_prefix=args.uriprefix)
if args.action == 'get':
    n_rows = p.get(args.src, args.inter, args.intra)
    print datetime.now(), n_rows, "rows in", args.src
elif args.action == 'update':
    [add_graph, sub_graph] = p.update(args.src, args.inter, args.intra)
    add_file = open(args.rdfprefix + '_add.rdf', 'w')
    print >>add_file, add_graph.serialize(format='nt')
    add_file.close()
    sub_file = open(args.rdfprefix + '_sub.rdf', 'w')
    print >>sub_file, sub_graph.serialize(format='nt')
    sub_file.close()
    print datetime.now(), len(add_graph), 'triples to add', len(sub_graph), 'triples to sub'
elif args.action == 'summarize':
    print p.summarize()
elif args.action == 'serialize':
    print p.serialize()
else:
    print datetime.now(), "Unknown action.  Try sv -h for help"
print datetime.now(), "Finish"
Esempio n. 23
0
class Manager:
    AUTO_START_GPIO_PIN = 16
    ONCE_BY_HOUR_TICK = 360  # 1h

    def __init__(self, refPath, dataPath, dbFilename):
        GPIO.cleanup()
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.AUTO_START_GPIO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        self.__i2c = I2C(2)
        self.__analog = Analog(sel.__i2c.getLock(), 0x49)
        self.default = Default()
        self.database = Database(dataPath, dbFilename)
        self.waterlevel = Waterlevel(debug, self.database)
        self.light = Light(self.database)
        self.curtain = Curtain(self.database)
        self.pressure = Pressure(self.database, self.default, self.__analog)
        self.temperature = Temperature("28-0417716a37ff", self.database)
        self.redox = Redox(debug, self.database, self.default, self.__analog)
        self.ph = PH(debug, self.database, self.default, self.__analog,
                     self.temperature)
        self.robot = Robot(debug, self.database)
        self.pump = Pump(debug, self.database, self.default, self.robot,
                         self.redox, self.ph, self.temperature)
        self.panel = Panel(debug, self.database, self.default, self.pump,
                           self.redox, self.ph, self.__i2c)
        self.statistic = Statistic(debug, self.pump, self.robot, self.redox,
                                   self.ph, self.temperature, self.pressure,
                                   self.waterlevel)
        self.refPath = refPath
        self.__autoSaveTick = 0
        self.__today = date.today().day - 1
        debug.TRACE(debug.DEBUG, "Initialisation done (Verbosity level: %s)\n",
                    debug)

    def __del__(self):
        GPIO.cleanup()

    def __onceByHour(self):
        if self.__autoSaveTick == self.ONCE_BY_HOUR_TICK:
            self.database.backup()
            self.__autoSaveTick = 0
            # All seems to be OK, we can remove the previous version
            backup = os.path.join(self.refPath, "PoolSurvey_bak")
            if os.path.exists(backup):
                os.system("rm -frd %s" % backup)
        self.__autoSaveTick += 1

    def __onceByDay(self):
        if self.__today != date.today().day:
            self.__today = date.today().day
            self.pressure.onceByDay()
            self.pump.onceByDay()
            self.statistic.onceByDay()

    def isAutoStart(self):
        return GPIO.input(self.AUTO_START_GPIO_PIN) == GPIO.LOW

    def start(self):
        debug.TRACE(debug.DEBUG, "Manager is started\n")
        self.__running = True
        while self.__running:
            debug.TAG(debug.DETAIL, "%ds Tick" % REFRESH_TICK)
            self.temperature.update()
            self.__onceByDay()
            self.pump.update()
            if self.pump.guardPeriodElapsed():
                self.robot.update()
                self.ph.update()
                self.redox.update()
                self.waterlevel.update()
                self.pressure.update()
                self.panel.update()
            self.statistic.update()
            self.__onceByHour()
            time.sleep(REFRESH_TICK)
        debug.TRACE(debug.DEBUG, "Manager is stopped\n")
        self.pump.switchOff()
        self.statistic.save()

    def stop(self):
        self.__running = False
Esempio n. 24
0
 def test_not_found(self):
     p = Pump("data/person_def.json", verbose=True)
     p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n12345678',
                            u'remove': u'True'}}
     [add, sub] = p.update()
     self.assertTrue(len(add) == 0 and len(sub) == 0)
Esempio n. 25
0
 def test_small_case(self):
     p = Pump("data/person_def.json", verbose=True)
     p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n2084211328',
                            u'remove': u'True'}}
     [add, sub] = p.update()
     self.assertTrue(len(add) == 0 and len(sub) == 1)
Esempio n. 26
0
 def test_no_update_file(self):
     p = Pump()
     with self.assertRaises(IOError):
         p.update('data/no_update_file.txt')
Esempio n. 27
0
 def test_normal_inject(self):
     p = Pump()
     p.update_data = {1: {u'uri': u'http://vivo.ufl.edu/individual/n8984374104', u'abbreviation': u'None'}}
     p.update()
     self.assertTrue("8984374104" in str(p.update_data))  # Using the injected data, not default
Esempio n. 28
0
 def test_missing_uri_column_inject(self):
     p = Pump()
     p.update_data = {1: {u'overview': u'None'}}
     with self.assertRaises(KeyError):
         p.update()
Esempio n. 29
0
 def test_default_usage(self):
     p = Pump()
     p.update()
     self.assertTrue("data/pump_def.json" in p.summarize())  # Using the default definition