Exemplo n.º 1
0
    def diagnostics(self):
        """
        >>> Product('DGKFL06JDHJP').diagnostics()
        """
        if hasattr(self, "alternateDeviceId"):
            diags = Diagnostics(alternateDeviceId=self.alternateDeviceId)
        else:
            diags = Diagnostics(serialNumber=self.serialNumber)

        return diags.fetch()
Exemplo n.º 2
0
    def __init__(self, hdf5_file, nPlot=1):
        '''
        Constructor
        '''

        self.diagnostics = Diagnostics(hdf5_file)

        self.nPlot = nPlot
        self.plot = PlotMHD2D(self.diagnostics, self.diagnostics.nt, nPlot)
Exemplo n.º 3
0
    def __init__(self, hdf5_file, nPlot=1, ntMax=0):
        '''
        Constructor
        '''

        self.diagnostics = Diagnostics(hdf5_file)

        if ntMax > 0 and ntMax < self.diagnostics.nt:
            self.nt = ntMax
        else:
            self.nt = self.diagnostics.nt

        self.plot = PlotMHD2D(self.diagnostics,
                              args.hdf5_file.replace(".hdf5", ""), self.nt,
                              nPlot)
Exemplo n.º 4
0
    def __init__(self, hdf5_file, nPlot=1, ntMax=0, write=False):
        '''
        Constructor
        '''

        self.diagnostics = Diagnostics(hdf5_file)

        if ntMax > 0 and ntMax < self.diagnostics.nt:
            self.nt = ntMax
        else:
            self.nt = self.diagnostics.nt

        self.nPlot = nPlot
        self.plot = PlotMHD2D(self.diagnostics, self.diagnostics.nt, self.nt,
                              nPlot, write)
    def requires(self):

        # Public sources
        yield PostsToDb()

        # Internal sources
        yield GomusToDb()

        # Analysis tasks
        yield AspectBasedSentimentAnalysis()
        yield TopicModeling()
        yield PredictionsToDb()

        # Diagnostics
        yield Diagnostics()

        # Extended Tweet Gathering
        yield TwitterExtendedDatasetToDB()
    def __init__(self, model_root, data_dir, communities=None, tag=None):
        """
        initilizer 
        
        inputs:
            model_root: model root path <string>
            communities: list of communities to setup <string>
            data_repo: path to data repo <sting>
            tag: (optional) tag to use as self.tag setup sub directory,
                if not provided self.tag will be m<version>_d<version> <string> 
            
        postconditions:
            see invatiants
        """
        self.model_root = model_root
        self.communities = communities
        self.data_dir = data_dir

        self.tag = tag
        if tag is None:
            self.tag = self.make_version_tag()
        self.diagnostics = Diagnostics()
Exemplo n.º 7
0
                        type=int,
                        default=1,
                        help='plot every i\'th frame')
    parser.add_argument('-ntmax',
                        metavar='i',
                        type=int,
                        default=0,
                        help='limit to i points in time')

    args = parser.parse_args()

    print
    print("Replay run with " + args.hdf5_file)
    print

    diagnostics = Diagnostics(args.hdf5_file)

    ntMax = args.ntmax
    nPlot = args.np

    if ntMax > 0 and ntMax < diagnostics.nt:
        nt = ntMax
    else:
        nt = diagnostics.nt

    plot = PlotEnergy(diagnostics, args.hdf5_file.replace(".hdf5", ""), nt,
                      nPlot)

    print
    print("Replay finished.")
    print
    def __init__ (self, community_config, global_config = None, diag = None, 
        scalers = {'diesel price':1.0, 'diesel price adder':0},
        intertie_config = None):
        """This class manages the input data for the an AAEM model instance
        
        Parameters
        ----------
        community_config: path to yaml file or dict
            the dictionary or dictionary that would be loaded from the yaml file 
        should match the format to be validated for the model to run, unless
        global_config is also provided, in which case all config values not 
        provided here have values in global_config
        global_config: path to yaml file or dict, optional
            Optional second config file of values that can be applied to many
        model instances
        diag: Diagnostics, optional
            AAEM Diagnostics object for tracking messages from model
        scalers: Dict, optional
            Scalers to change model behaviour. The keys 'diesel price' and
        'diesel price adder' are used in CommunityData, and will be multiplied 
        or added to the diesel prices respectively. This will carry over into
        the electirc non-fuel prices.
        
        Attributes
        ----------
        data: Dict
            Configuration data for model instance
        diagnostics:Diagnostics
            AAEM Diagnostics object for tracking messages from model
        intertie: str, or None
            status to track intertie placment, 'parent', 'child', or None
        intertie_data: CommunityData
            config data for the entire intertie if community is a 
        child community 
        
        
        """
        self.diagnostics = diag
        if diag == None:
            self.diagnostics = Diagnostics()
            
        if type(community_config) is dict and type(global_config) is dict:
            self.data = merge_configs(self.load_structure(), global_config)
            self.data = merge_configs(self.data, community_config)
        else: 
            self.data = self.load_config(community_config, global_config)
            
            
        valid, reason = self.validate_config()
        if not valid:
            raise StandardError, 'INVALID CONFIG FILE: ' + reason

        self.intertie = None
        
        intertie = self.get_item('community', 'intertie')
        if type (intertie) is list:
            if self.get_item('community', 'model as intertie') :
                self.intertie = 'parent'
            else:
                self.intertie = 'child'
         
        self.intertie_data = None
        
        ## load if community is part of an intertie but not the intertie 
        ## it's self. I.E. load info for Bethel or Oscarville,
        ## but not Bethel_intertie
        if not self.intertie is None and \
                not self.get_item('community', 'model as intertie'):
            self.diagnostics.add_note(
                'Community Data',
                'Attempting to find intertie data'
            )
            ## is the intertie_config a dict of file, also use same globals
            if type(intertie_config) is dict \
                    or (type(intertie_config) is str \
                    and os.path.isfile(intertie_config)):
                self.diagnostics.add_note(
                    'Community Data',
                    'using provided intertie_config argument'
                )
                self.intertie_data = CommunityData(
                    intertie_config, 
                    global_config,
                    self.diagnostics,
                    scalers
                )
            ## try to find the file
            elif os.path.isfile(community_config):
                rt_path = os.path.split(community_config)
                it_file = \
                    self.get_item('community','intertie')[0].\
                        replace(' ','_').replace("'",'')\
                     + '_intertie.yaml'
                it_file = os.path.join(rt_path[0], it_file)
                if os.path.isfile(it_file):
                    self.diagnostics.add_note(
                        'Community Data',
                        'Found interte data at ' + it_file
                    )
                    
                    self.intertie_data = CommunityData(
                        it_file,
                        global_config,
                        self.diagnostics,
                        scalers
                    )
            else:
                self.diagnostics.add_note(
                    'Community Data',
                    'Could not find intertie_data Leaving it as None'
                )
                ## self.intertie_data = None is initlized 
                
                        
        ## component spesifc plugins
        for comp in comp_order:
            config = import_module("aaem.components." + comp_lib[comp]).config
            try:
                plugins = config.plugins
            except AttributeError:
                continue
                
            for plugin in plugins:
                plugin(self, community_config, global_config, scalers)
         
        convert = self.data['community']['diesel prices']
        convert.index = [int(y) for y in convert.index]
        convert.index.name = 'year'
        convert = self.data['community']['electric prices']
        convert.index = [int(y) for y in convert.index]
        convert.index.name = 'year'
        # modify diesel prices and electric prices
        self.apply_scalers(scalers)

    
        self.check_auto_disable_conditions ()
Exemplo n.º 9
0
from flask import Flask
from flask import request
from google.auth.transport.urllib3 import AuthorizedHttp
from google.oauth2 import service_account

from diagnostics import Diagnostics
import settings

app = Flask(__name__)

credentials = service_account.Credentials.from_service_account_info(
    json.loads(settings.GOOGLE_SERVICE_ACCOUNT_CREDENTIALS_JSON),
    scopes=['https://www.googleapis.com/auth/bigquery.insertdata'])

diagnostics = Diagnostics(launched_at=datetime.datetime.utcnow())


@app.route('/log', methods=['POST'])
def log():
    diagnostics.request_count += 1
    auth = request.authorization
    if not auth or auth.username != settings.LOG_DRAIN_USERNAME or auth.password != settings.LOG_DRAIN_PASSWORD:
        diagnostics.unauthorized_count += 1
        return '', 403
    diagnostics.authorized_count += 1

    log_records = []
    for log_line in _parse_log_lines(request.data):
        if log_line.startswith(settings.LOG_RECORD_PREFIX):
            json_string = log_line.replace(settings.LOG_RECORD_PREFIX, '',
    def run(self,
            community_config,
            global_config=None,
            tag='',
            scalers=None,
            alt_save_name=None):
        """
        run the model for a community
        
        inputs:
            community: the community <string>
            c_config: (optional, default: none) alternate community config 
                file <string>
            g_config: (optional, default: none) alternat global confing 
                file <string>
            tag: (optional) tag for results dir <string>
            
        outputs:
            the model is run for a community/project/assigned 'name'
            
        preconditions:
            see invariants
            
        postconditions:
            None
        """
        #~ print community_config

        if scalers is None:
            scalers = default_scalers

        #~ if name is None:
        #~ name = community

        temp = tag
        #~ if img_dir is None:
        #~ if temp != '':
        #~ temp = '_' + tag
        #~ img_dir = os.path.join(self.model_root, 'results' + temp, 'plots')

        #~ cd, fc, diag = self.setup_community(community, i_dir, c_config,
        #~ g_config, c_mult, scalers)

        diagnostics = Diagnostics()
        community_data = CommunityData(community_config, global_config,
                                       diagnostics, scalers)
        name = community_data.get_item('community', 'file id')
        #~ print name
        forecast = Forecast(community_data, diagnostics, scalers)

        comps_used = self.run_components(community_data, forecast, diagnostics,
                                         scalers)

        #~ name = community_data.get_item('community', 'file id')
        self.save_components_output(comps_used,
                                    name,
                                    forecast,
                                    tag,
                                    alt_name=alt_save_name)
        #~ self.save_forecast_output(forecast, name, img_dir, plot, tag)
        self.save_input_files(community_data,
                              name,
                              tag,
                              alt_name=alt_save_name)
        self.save_diagnostics(diagnostics, name, tag, alt_name=alt_save_name)

        comps_used['community data'] = community_data
        comps_used['forecast'] = forecast

        #~ print name
        #~ print 'rb', alt_save_name
        self.store_results(comps_used, tag, name=alt_save_name)
    def __init__(self,
                 community_data,
                 diag=None,
                 scalers={'kWh consumption': 1.0}):
        """
        pre:
            self.cd is a community_data instance. 
        post:
            self.start_year < self.end_year are years(ints) 
            self.cd is a community_data instance. 
        """
        self.diagnostics = diag
        if self.diagnostics == None:
            self.diagnostics = Diagnostics()
        self.cd = community_data

        self.forecast_population()

        #~ ## test block
        #~ self.forecast_consumption(scalers['kWh consumption'])
        #~ self.forecast_generation()
        #~ return

        if self.cd.get_item("community", "model electricity") is False:
            pass
        else:
            try:
                self.forecast_consumption(scalers['kWh consumption'])
                self.forecast_generation()

                self.forecast_average_kW()
            except RuntimeError:
                self.cd.set_item("community", "model financial", False)
                self.cd.set_item("community", "model electricity", False)
                self.diagnostics.add_warning(
                    'Forecast',
                    ('Electricity data was insufficient to model'
                     ' electricity or financial values. In community data'
                     ' model financial, and model electricity have been'
                     ' set to false.'))

        self.calc_average_diesel_load()

        self.cpi = np.array(self.cd.get_item('community', 'cpi multipliers'))
        #~ DataFrame([
        #~ 1, 0.9765625, 0.953674316, 0.931322575, 0.909494702, 0.88817842,
        #~ 0.867361738, 0.847032947, 0.827180613, 0.807793567, 0.788860905,
        #~ 0.770371978, 0.752316385, 0.734683969, 0.717464814, 0.700649232,
        #~ 0.684227766, 0.668191178, 0.652530447, 0.637236765, 0.622301528,
        #~ 0.607716336, 0.593472984, 0.579563461, 0.565979942, 0.552714788,
        #~ 0.539760535, 0.527109897, 0.514755759, 0.502691171, 0.490909347,
        #~ 0.479403659, 0.468167636, 0.457194957, 0.44647945, 0.436015088,
        #~ 0.425795984, 0.415816391, 0.406070694, 0.396553412, 0.387259192,
        #~ 0.378182804, 0.369319145, 0.360663227, 0.352210183, 0.343955257,
        #~ 0.335893805, 0.328021294, 0.320333295, 0.312825484, 0.305493636,
        #~ 0.298333629, 0.291341435, 0.28451312, 0.277844844, 0.271332855,
        #~ 0.264973491, 0.258763175, 0.252698413, 0.246775794, 0.240991987],
        #~ )
        #~ last_cpi_year = self.cpi.index.tolist()[-1]
        #~ if self.end_year < last_cpi_year:
        #~ self.cpi = self.cpi[:self.end_year]
        #~ elif self.end_year > last_cpi_year:
        #~ self.diagnostics.add_note("Forecast",
        #~ "extending cpi past avaiable data")
        #~ last_cpi = float(self.cpi.ix[last_cpi_year])
        #~ for i in range(last_cpi_year,self.end_year+1):
        #~ self.cpi.ix[i] = last_cpi

        #~ self.forecast_households()
        self.heat_demand_cols = []
        self.heating_fuel_cols = []
        self.electric_columns = []
Exemplo n.º 12
0
class MainScreen(App):

    ser_bytes = NumericProperty()
    ser = serial.Serial(baudrate=115200)
    data = ListProperty([0,0,0,0,0,0])
    info = ObjectProperty()
    errors = []
    sm = ScreenManager()
    main = Main(name='main')
    data_screen = Data_Screen(name='data')
    diagnostics = Diagnostics(name='diagnostics')
    sm.add_widget(main)
    sm.add_widget(data_screen)
    sm.add_widget(diagnostics)


    def build(self):
        Window.clearcolor = (0, 0, 0, 1)
        Window.fullscreen = 'auto'
        Window.bind(on_key_down=self.press)

        #create data dictionary
        self.info = extract('telemetry2.xlsx')
        self.main.info = self.info
        self.diagnostics.info = self.info
        self.diagnostics.tabs.info = self.info 

        #Clock.schedule_interval(self.readserial, 0.05)
        Clock.schedule_interval(self.noserial, 0.5)
        return self.sm
    
    #keyboard inputs
    def press(self, keyboard, keycode, text, modifiers, type):
        if keycode == 275: # ascii code for left
            if self.sm.current == 'main':
                self.sm.transition = SlideTransition(direction="left")
                self.sm.current = 'data'
            elif self.sm.current == 'diagnostics':
                self.sm.transition = SlideTransition(direction="left")
                self.sm.current = 'main'
        elif keycode == 276: # ascii code for right 
            if self.sm.current == 'main':
                self.sm.transition = SlideTransition(direction="right")
                self.sm.current = 'diagnostics'
            elif self.sm.current == 'data':
                self.sm.transition = SlideTransition(direction="right")
                self.sm.current = 'main'
        elif keycode == 27: # ascii code for ESC
            App.stop(self)
        elif keycode == 273: #up
            if self.sm.current == 'diagnostics':
                if self.diagnostics.tabs.opacity == 0: # reset
                    self.diagnostics.rv.pos_hint = {"x": 0.02, "y": 0.02}
                    self.diagnostics.rv.size_hint = (0.7, 0.2)
                    self.diagnostics.tabs.pos_hint = {"x": 0.02, "y": 0.25}
                    self.diagnostics.tabs.size_hint = (0.7, 0.65)
                    self.diagnostics.tabs.opacity = 1
                else:
                    self.diagnostics.rv.pos_hint= {"x": 0.02, "y": 0.02}
                    self.diagnostics.rv.size_hint = (0.7, 0.05)
                    self.diagnostics.tabs.pos_hint = {"x": 0.02, "y": 0.08}
                    self.diagnostics.tabs.size_hint = (0.7, 0.9)
        elif keycode == 274: #down
            if self.sm.current == 'diagnostics':
                if self.diagnostics.tabs.size_hint[1] == 0.9: # reset
                    self.diagnostics.rv.pos_hint = {"x": 0.02, "y": 0.02}
                    self.diagnostics.rv.size_hint = (0.7, 0.2)
                    self.diagnostics.tabs.pos_hint = {"x": 0.02, "y": 0.25}
                    self.diagnostics.tabs.size_hint = (0.7, 0.65)
                else:
                    self.diagnostics.rv.pos_hint = {"x": 0.02, "y": 0.02}
                    self.diagnostics.rv.size_hint = (0.7, 0.95)
                    self.diagnostics.tabs.pos_hint = {"x": 0.02, "y": 0.06}
                    self.diagnostics.tabs.size_hint = (0.7, 0)
                    self.diagnostics.tabs.opacity = 0
        return True

    
    def readserial(self, dt):
        try:
            global ser
            if ser.in_waiting:
                #print(ser.in_waiting)
                #length = ser.in_waiting
                #temp = ser.readline()
                self.data = ser.readline().split()
                ser.reset_input_buffer()
                #print(len(self.data))
                #print(self.data[23])
                self.main.data = self.data
                #print(len(self.main.data))
                #print(str(int(self.data[28])))
                #self.diagnostics.data = self.data
                #self.data_screen.data = self.data
        except Exception as e:
            print(e)
            self.main.pc_status.serial_status = False
            try:
                ser = serial.Serial(
                    baudrate='115200',
                    timeout=1,
                    port=str(serial.tools.list_ports.comports()[0]).split()[0]
                    #port="/dev/ttyUSB0"
                )
                self.main.pc_status.serial_status = True
            except Exception:
                pass

    def noserial(self, dt):
        self.data = [random.randint(0,255) for i in range(60)] #instead of readserial

        #passes all the values 
        self.main.data = self.data
        self.diagnostics.update(self.data)
        #self.data_screen.data = self.data




    def update_errors2(self):
        self.errors = []
        for i in range(len(self.data)):
            self.errors.append(0)
        if int(self.data[7]) > 80:
            self.errors[7] = 2


    def update_errors(self):
        #stringA
        if self.data[0] == 0:
            for i in range(1,250):
                if self.data[i] > 250 or self.data[i] < 5:
                    self.errors.append({'datapos':i, 'value': self.data[i], 'timestamp': datetime.now().strftime("%H:%M:%S")})
        #stringB
        elif self.data[0] == 1:
            pass
        #stringC
        elif self.data[0] == 2:
            pass
        #log and remove the errors  if they bunch up
        if len(self.errors) > 20:
            self.errors = []
Exemplo n.º 13
0
 def diagnostics(self):
     """
     >>> Product('DGKFL06JDHJP').diagnostics()
     """
     diags = Diagnostics(serialNumber=self.serialNumber)
     return diags.fetch()
Exemplo n.º 14
0
from people import Customer

from logplot import LogPlot
from diagnostics import Diagnostics

C = Customer('Self', 1)

diagnostics = Diagnostics()
results = diagnostics.from_file(
    'C:\\Users\\Imraan\\PycharmProjects\\crossLang\\corellian_74G.log')
LogPlot().plot(results, './results')

A = Customer('Imraan', 30)

C.deposit(50)