C++: Added scriptdependentpricespecification
authorjani <jani@asema.com>
Wed, 13 Mar 2019 11:53:14 +0000 (13:53 +0200)
committerjani <jani@asema.com>
Wed, 13 Mar 2019 11:53:14 +0000 (13:53 +0200)
Common/C++/SmartAPI/smartapi.pro
Common/C++/SmartAPI/smartapi/common/ClassMapper.h
Common/C++/SmartAPI/smartapi/common/PROPERTY.h
Common/C++/SmartAPI/smartapi/model/ScriptDependentPriceSpecification.cpp [new file with mode: 0644]
Common/C++/SmartAPI/smartapi/model/ScriptDependentPriceSpecification.h [new file with mode: 0644]
Common/Java/SmartAPI/src/smartapi/agents/OntologyAgent.java
Common/Java/SmartAPI/src/smartapi/common/ConceptValidator.java
Common/Python/SmartAPI/tests/TestRegistrationAgent.py

index 932d7e9def50e961c00b09b0130eccf0f7788636..2e448cd4edffc0ec2cb603159a6e67c943fa0226 100644 (file)
@@ -166,6 +166,7 @@ SOURCES += smartapi/agents/Agent.cpp \
         smartapi/model/LinearCalculation.cpp \
         smartapi/model/TravelDistanceDependentPriceSpecification.cpp \
         smartapi/model/DistanceDependentPriceSpecification.cpp \
+        smartapi/model/ScriptDependentPriceSpecification.cpp \
         smartapi/model/ZoneDependentPriceSpecification.cpp \
         smartapi/model/ZonePopulationDependentPriceSpecification.cpp \
         smartapi/model/ZoneTravelDependentPriceSpecification.cpp \
@@ -308,6 +309,7 @@ HEADERS += smartapi/agents/Agent.h \
         smartapi/model/LinearCalculation.h \
         smartapi/model/TravelDistanceDependentPriceSpecification.h \
         smartapi/model/DistanceDependentPriceSpecification.h \
+        smartapi/model/ScriptDependentPriceSpecification.h \
         smartapi/model/ZoneDependentPriceSpecification.h \
         smartapi/model/ZonePopulationDependentPriceSpecification.h \
         smartapi/model/ZoneTravelDependentPriceSpecification.h \
index ca28bc545d5c8eab9a27717435f71e61dd38557e..44c934ca730c9de2076091d958b01422ef9aec58 100644 (file)
@@ -62,6 +62,7 @@
 #include "smartapi/model/DurationDependentPriceSpecification.h"
 #include "smartapi/model/TravelDistanceDependentPriceSpecification.h"
 #include "smartapi/model/DistanceDependentPriceSpecification.h"
+#include "smartapi/model/ScriptDependentPriceSpecification.h"
 #include "smartapi/model/ZoneDependentPriceSpecification.h"
 #include "smartapi/model/ZoneTravelDependentPriceSpecification.h"
 #include "smartapi/model/TravelDistanceDurationDependentPriceSpecification.h"
@@ -191,6 +192,7 @@ public:
                if (type == RESOURCE__LINEARCALCULATION) return new LinearCalculation();
                if (type == RESOURCE__TRAVELDISTANCEDEPENDENTPRICESPECIFICATION) return new TravelDistanceDependentPriceSpecification();
                if (type == RESOURCE__DISTANCEDEPENDENTPRICESPECIFICATION) return new DistanceDependentPriceSpecification();
+               if (type == RESOURCE__SCRIPTDEPENDENTPRICESPECIFICATION) return new ScriptDependentPriceSpecification();
                if (type == RESOURCE__ZONEDEPENDENTPRICESPECIFICATION) return new ZoneDependentPriceSpecification();
                if (type == RESOURCE__ZONETRAVELDEPENDENTPRICESPECIFICATION) return new ZoneTravelDependentPriceSpecification();
                if (type == RESOURCE__TRAVELDISTANCEDURATIONDEPENDENTPRICESPECIFICATION) return new TravelDistanceDurationDependentPriceSpecification();
@@ -271,6 +273,7 @@ public:
                if (type == RESOURCE__LINEARCALCULATION) return new LinearCalculation((LinearCalculation*)o);
                if (type == RESOURCE__TRAVELDISTANCEDEPENDENTPRICESPECIFICATION) return new TravelDistanceDependentPriceSpecification((TravelDistanceDependentPriceSpecification*)o);
                if (type == RESOURCE__DISTANCEDEPENDENTPRICESPECIFICATION) return new DistanceDependentPriceSpecification((DistanceDependentPriceSpecification*)o);
+               if (type == RESOURCE__SCRIPTDEPENDENTPRICESPECIFICATION) return new ScriptDependentPriceSpecification((ScriptDependentPriceSpecification*)o);
                if (type == RESOURCE__ZONEDEPENDENTPRICESPECIFICATION) return new ZoneDependentPriceSpecification((ZoneDependentPriceSpecification*)o);
                if (type == RESOURCE__ZONETRAVELDEPENDENTPRICESPECIFICATION) return new ZoneTravelDependentPriceSpecification((ZoneTravelDependentPriceSpecification*)o);
                if (type == RESOURCE__TRAVELDISTANCEDURATIONDEPENDENTPRICESPECIFICATION) return new TravelDistanceDurationDependentPriceSpecification((TravelDistanceDurationDependentPriceSpecification*)o);
@@ -350,6 +353,7 @@ public:
                if (LinearCalculation* oo                                                                       = dynamic_cast<LinearCalculation*>(o)) { return oo; }
                if (TravelDistanceDependentPriceSpecification* oo                       = dynamic_cast<TravelDistanceDependentPriceSpecification*>(o)) { return oo; }
                if (DistanceDependentPriceSpecification* oo                                     = dynamic_cast<DistanceDependentPriceSpecification*>(o)) { return oo; }
+               if (ScriptDependentPriceSpecification* oo                                       = dynamic_cast<ScriptDependentPriceSpecification*>(o)) { return oo; }
                if (ZoneDependentPriceSpecification* oo                                         = dynamic_cast<ZoneDependentPriceSpecification*>(o)) { return oo; }
                if (ZoneTravelDependentPriceSpecification* oo                           = dynamic_cast<ZoneTravelDependentPriceSpecification*>(o)) { return oo; }
                if (TravelDistanceDurationDependentPriceSpecification* oo       = dynamic_cast<TravelDistanceDurationDependentPriceSpecification*>(o)) { return oo; }
@@ -426,6 +430,7 @@ public:
                if (LinearCalculation* oo                                                                       = dynamic_cast<LinearCalculation*>(o)) return oo->serialize(model);
                if (TravelDistanceDependentPriceSpecification* oo                       = dynamic_cast<TravelDistanceDependentPriceSpecification*>(o)) return oo->serialize(model);
                if (DistanceDependentPriceSpecification* oo                                     = dynamic_cast<DistanceDependentPriceSpecification*>(o)) return oo->serialize(model);
+               if (ScriptDependentPriceSpecification* oo                                       = dynamic_cast<ScriptDependentPriceSpecification*>(o)) return oo->serialize(model);
                if (ZoneDependentPriceSpecification* oo                                         = dynamic_cast<ZoneDependentPriceSpecification*>(o)) return oo->serialize(model);
                if (ZoneTravelDependentPriceSpecification* oo                           = dynamic_cast<ZoneTravelDependentPriceSpecification*>(o)) return oo->serialize(model);
                if (TravelDistanceDurationDependentPriceSpecification* oo       = dynamic_cast<TravelDistanceDurationDependentPriceSpecification*>(o)) return oo->serialize(model);
index a644d710dedf88c31f7635c1745248b6841b8e03..117b5652066feeb93260c7e01a493fe4b862d7c4 100644 (file)
 #define PROPERTY__ZONENUMBER           "http://smart-api.io/ontology/1.0/smartapi#zoneNumber"
 #define PROPERTY__ZONEROUTE            "http://smart-api.io/ontology/1.0/smartapi#zoneRoute"
 
+#define PROPERTY__PROGRAMCODE          "http://smart-api.io/ontology/1.0/smartapi#programCode"
+
 #endif //__PROPERTY_H__
diff --git a/Common/C++/SmartAPI/smartapi/model/ScriptDependentPriceSpecification.cpp b/Common/C++/SmartAPI/smartapi/model/ScriptDependentPriceSpecification.cpp
new file mode 100644 (file)
index 0000000..a93f298
--- /dev/null
@@ -0,0 +1,54 @@
+#include "ScriptDependentPriceSpecification.h"
+
+#include "smartapi/common/RESOURCE.h"
+#include <QtDebug>
+
+
+ScriptDependentPriceSpecification::ScriptDependentPriceSpecification(QString identifierUri) :
+       DependentPriceSpecification(identifierUri)
+{
+       setType(RESOURCE__SCRIPTDEPENDENTPRICESPECIFICATION);
+       INIT_PROPERTY(mScript);
+}
+
+ScriptDependentPriceSpecification::ScriptDependentPriceSpecification(QString unit, QString secondaryUnit, QString secondaryQuantity, QDateTime validFrom, QDateTime validThrough) :
+       DependentPriceSpecification()
+{
+       setQuantity(RESOURCE__CURRENCY);
+       setUnit(unit);
+       setSecondaryUnit(secondaryUnit);
+       setSecondaryQuantity(secondaryQuantity);
+       setValidFrom(validFrom);
+       setValidThrough(validThrough);
+       INIT_PROPERTY(mScript);
+}
+
+ScriptDependentPriceSpecification::ScriptDependentPriceSpecification(ScriptDependentPriceSpecification* o) :
+       DependentPriceSpecification(o)
+{
+       setType(RESOURCE__SCRIPTDEPENDENTPRICESPECIFICATION);
+       SET_PROPERTY_REFERENCE(PROPERTY__PROGRAMCODE,mScript,Variant);
+}
+
+ScriptDependentPriceSpecification::~ScriptDependentPriceSpecification()
+{
+}
+
+void ScriptDependentPriceSpecification::clearReferences(QSet<GraphItem*>* trash)
+{
+       INIT_CLEAR(DependentPriceSpecification,trash);
+       FINISH_CLEAR(DependentPriceSpecification,trash);
+}
+
+Resource* ScriptDependentPriceSpecification::serialize(Model* model)
+{
+       INIT_SERIALIZE(DependentPriceSpecification,model)
+       FINISH_SERIALIZE(DependentPriceSpecification)
+}
+
+void ScriptDependentPriceSpecification::parse(Statement* statement)
+{
+       INIT_PARSE(statement)
+       PARSE_PROPERTY(PROPERTY__PROGRAMCODE, setScript, Variant)
+       FINISH_PARSE(DependentPriceSpecification)
+}
diff --git a/Common/C++/SmartAPI/smartapi/model/ScriptDependentPriceSpecification.h b/Common/C++/SmartAPI/smartapi/model/ScriptDependentPriceSpecification.h
new file mode 100644 (file)
index 0000000..22fb44a
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef SCRIPTDEPENDENTPRICESPECIFICATION_H
+#define SCRIPTDEPENDENTPRICESPECIFICATION_H
+
+#include "DependentPriceSpecification.h"
+
+#include "smartapi/common/PROPERTY.h"
+
+
+class ScriptDependentPriceSpecification : public DependentPriceSpecification
+{
+
+public:
+       ScriptDependentPriceSpecification(QString identifierUri = QString());
+       ScriptDependentPriceSpecification(QString unit, QString secondaryUnit, QString secondaryQuantity, QDateTime validFrom, QDateTime validThrough);
+       ScriptDependentPriceSpecification(ScriptDependentPriceSpecification* o);
+       ~ScriptDependentPriceSpecification();
+
+       virtual void clearReferences(QSet<GraphItem*>* trash);
+       Resource* serialize(Model* model);
+       void parse(Statement* statement);
+
+       bool hasScript()                                                                        { return mScript != NULL; }
+       QString getScript()                                                                     { IDENTIFIERSTRINGPROPERTYVAL(mScript, asString, QString()); }
+       void setScript(QString script)                                          { setScript(new Variant(script)); }
+       void setScript(Variant* script)                                         { set(PROPERTY__PROGRAMCODE, script); mScript = script; }
+
+private:
+       Variant* mScript;
+};
+
+#endif // SCRIPTDEPENDENTPRICESPECIFICATION_H
index ad6a6f78022fe80bb0db5dd82f49336005eac1eb..dcb2f5e4471fa990a438d6330d905a1e91daccb4 100644 (file)
@@ -24,11 +24,8 @@ import smartapi.model.Obj;
 public class OntologyAgent {
 
        public static String ontologyFolderPath = "ontologies/";
-       
        private static String ontologyDownloadUriPrefix = "http://talk.smart-api.io/ontology/";
-       
        private static String checksumFilePath = "checksum.properties";
-       
        private static Properties checksumProperties = null;
 
        public OntologyAgent()
@@ -128,20 +125,20 @@ public class OntologyAgent {
        {
                try{
                        for (Map.Entry<String,String> entry : Tools.prefixes.entrySet()) {
-                               Tools.downloadFile(OntologyAgent.getOntologyDownloadUri(entry.getValue()), OntologyAgent.ontologyFolderPath, entry.getKey() + ".ttl");                                                          
+                               Tools.downloadFile(OntologyAgent.getOntologyDownloadUri(entry.getValue()), OntologyAgent.ontologyFolderPath, entry.getKey() + ".ttl");
                        }
                        System.out.println("Successfully updated ontologies.");
                }catch(Exception e){
                        System.err.println("Error while downloading ontologies.");
                        e.printStackTrace();
-               }               
+               }
        }
        
        public static String getOntologyDownloadUri(String ontologyPrefixUri)
        {
                // remove last character of prefixUri if it is #
                if ( ontologyPrefixUri.endsWith("#") ) {
-                       ontologyPrefixUri = ontologyPrefixUri.substring(0, ontologyPrefixUri.length()-1);                       
+                       ontologyPrefixUri = ontologyPrefixUri.substring(0, ontologyPrefixUri.length()-1);
                }
                return OntologyAgent.ontologyDownloadUriPrefix + Tools.urlEncode(ontologyPrefixUri) + "/";
        }
index 1057a9146ddbbb0d1c83585d6a9e347791149755..f421c7cfa674df925dc9fdf34e2b49894f672f5c 100644 (file)
@@ -265,10 +265,12 @@ public class ConceptValidator {
                        // calculate concept grade from 0 to 10
                        conceptGrade = (1 - ((double)conceptErrorCount/numberOfTestedTriples)) * 10;
                }
+               
                //System.out.println((double)1/2);
                grading.setValueGrade(valueGrade);
                grading.setConceptGrade(conceptGrade);
                Tools.calculateGrade(grading);
+               
                // round grades to 2 digits
                grading.setValueGrade(((double)((int)(grading.getValueGrade().asDouble() *100.0)))/100.0);
                grading.setConceptGrade(((double)((int)(grading.getConceptGrade().asDouble() *100.0)))/100.0);
index ae92f463e23a5b7e3e02bd7be040a710d00e8344..cefbfdb8dc54188be1de04ab7c4f8b46bcdf1230 100755 (executable)
@@ -20,30 +20,48 @@ class TestRegistration(object):
         agent = RegistrationAgent(self.myIdentity)
         agent.setServerAddress(self.testingRegistrationUri)
         agent.setDebugMode(True)
-        print agent.getServerAddress()
         
         # registrate
         try:
-            s = Service.Service("http://smart-api.io/tests/python/registration/service/")
+            s = Service("http://smart-api.io/tests/python/registration/service/")
             s.setName("Registration Server Test Service")
-            a = Activity.Activity()
-            a.setMethod(RESOURCE.OPERATION)
-            s.addCapability(a)
+            
+            i = InterfaceAddress()
+            i.setHost("127.0.0.1")
+            i.setPath("/smart/v1.0e1.0")
+            i.setPort(80)
+            i.setScheme("http")
+            
+            write = Activity()
+            write.setMethod(RESOURCE.WRITE)
+            write.setInterface(i)
+            
+            read = Activity()
+            read.setMethod(RESOURCE.READ)
+            read.setInterface(i)
+            
+            s.addCapability(write)
+            s.addCapability(read)
+            
             s.setCoordinates(latitude=60.180824, longitude=24.832116)
             
-            power = ValueObject.ValueObject("http://smart-api.io/tests/python/registration/service/Cpower")
+            power = ValueObject("http://smart-api.io/tests/python/registration/service/Cpower")
+            power.addType(RESOURCE.READABLE)
+            power.addType(RESOURCE.WRITABLE)
             power.setQuantity(RESOURCE.POWER)
             power.setUnit(RESOURCE.WATT)
             power.setValue(6.5)
-            power.setMaximum(7.0)
+            power.setMaximum(1000.0)
+            power.setMinimum(0.0)
             s.addValueObject(power)
+            s.turtlePrint()
             
             agent.addEntity(s)
 
             r = agent.registrate()
             if r is None or r.hasErrors():
-                 print "RegistrationServerTest phase 1 FAILED (Registration)"
-                 return False
+                print "RegistrationServerTest phase 1 FAILED (Registration)"
+                return False
         except:
             traceback.print_exc()
             print "RegistrationServerTest phase 1 FAILED (Registration)"