예제 #1
0
    def inject(obj, session):
        if DEBUG:
            print "%s: input information: %s " % (TAG, obj);

        errors = {};
        preset = Session.__defaults__;
        preset.update(obj);           
        
        # Perform errors check
        if (preset["time_begin"] == None):    
            errors["time_begin"] = "time_begin couldn't have zero value, please check it";
            
        if (preset["time_end"] == None):      
            errors["time_end"] = "time_end couldn't have zero value, please check it";
            
        if (len(errors)):
            return session, obj, errors;
        
        # Create session element
        toBePushed = Session(obj["time_begin"], obj["time_end"]);  
        
        # Connect session with channels, there rules we are working with
        # 1. Scope object controls correctness of all information it contains
        # 2. Scope translates all information into one usual format
        
        scope = Scope.state();
        
        if DEBUG:
            print "%s: current scope %s" % (TAG, str(scope));
            
        if scope.has_key("channels") and len(scope["channels"]):
            for channel_title in scope["channels"]:
                if DEBUG:
                    print "Connection %s with <Channel %s>" % (str(session), channel_title);
                
                channel = session.query(Channel).filter_by(title=channel_title).first();

                if channel:                
                    toBePushed.channels.append(channel);
        
        session.add(toBePushed);
        session.flush();
        
        if DEBUG:
            print "%s: %s" % (TAG, toBePushed);
        
        Scope.inject({"sessions_id": toBePushed.id}, None, True);
        
        for i in Session.__defaults__.keys():
            del obj[i];
        
        return session, obj, {};
예제 #2
0
    def inject(obj, session):
        if DEBUG:
            print "%s: input information: %s " % (TAG, obj);
            
        errors = {};
        preset = MeasurementPoint.__defaults__;
        preset.update(obj);

        # Perform errors check
        if (preset['time'] == None):
            errors['time'] = "Time of Measurement point couldn't have Null value, please check it";
 
        # Create measurement point element
        # DESIGNING_QUATION: Can be set latitude and longitude without altitude in Measurement points?
        toBePushed = MeasurementPoint(preset['time'], preset['latitude'], preset["longitude"], preset["altitude"]);
        
        # Perform connection session option with session into 'session_id' field
        scope = Scope.state(); 
           
        if DEBUG:
            print "%s: current scope %s" % (TAG, str(scope));
                    
        if scope.has_key("sessions_id"):
            toBePushed.sessions_id = scope["session_id"]
        else:
            pass
            #WARNING: "Session id for Measurement points have zero value, is this not mistake?";

        if (len(errors)):
            return session, obj, errors;
        
        session.add(toBePushed);
        session.flush();
        
        Scope.inject({"measurement_point_id": toBePushed.id}, None, True);

        if DEBUG:
            print "%s: %s" % (TAG, toBePushed);
            
        for i in MeasurementPoint.__defaults__.keys():
            if i in obj.keys():
                del obj[i];
        
        return session, obj, {};                            
예제 #3
0
    def inject(obj, session):
        if DEBUG:
            print "%s: input information: %s " % (TAG, obj);

        errors = {};
        preset = SessionOption.__defaults__;
        preset.update(obj);
        
        # Perform errors check
        if (preset['title'] == None):
            errors['title'] = "Session option title couldn't have zero value, please check it";
        
        # Create session option element
        toBePushed = SessionOption(preset['title'], preset['sessions_options_value']);
        
        # Perform connection session option with session into 'session_id' field
        scope = Scope.state();
        
        if DEBUG:
            print "%s: current scope %s" % (TAG, str(scope));
            
        if scope.has_key("sessions_id"):
            toBePushed.sessions_id = scope["session_id"]
        else:
            errors['session_id'] = "Session id for session options couldn't have zero value, we should have information about session in json-file";
            
        if (len(errors)):
            return session, obj, errors;
        
        session.add(toBePushed);
        session.flush();
        
        if DEBUG:
            print "%s: %s" % (TAG, toBePushed);
        
        for i in SessionOption.__defaults__.keys():
            if i in obj.keys():
                del obj[i];
        
        return session, obj, {};   
예제 #4
0
    def inject(obj, session):
        if DEBUG:
            print "%s: input information: %s " % (TAG, obj);
            
        errors = {};
        preset = Measurement.__defaults__;
        preset.update(obj);
        
        # Perform errors check
        if (preset['measurement'] == None):
            errors['measurement'] = "Measurement couldn't have Null value, please check it";
            
        toBePushed = Measurement(preset['measurement'], preset['level_marker'], preset["relative_error"]);
       
        # Perform connection measurement with measurement_point, parameter and channel
        scope = Scope.state(); 

        if DEBUG:
            print "%s: current scope %s" % (TAG, str(scope));    
        
        if scope.has_key("measurement_point_id"):
            toBePushed.measurement_points_id = scope["measurement_point_id"]
        else:
            errors["measurement_point_id"] = "Measurement point for Measurement couldn't have Null value, please check it";
        
        if (len(errors)):
            return session, obj, errors;
        
        session.add(toBePushed);
        session.flush();
        
        if DEBUG:
            print "%s: %s" % (TAG, toBePushed);
        
        for i in Measurement.__defaults__.keys():
            if i in obj.keys():
                del obj[i];
            
        return session, obj, {};