Ejemplo n.º 1
0
    def initializeFromInternalPath(cls, referencePath, force =False):
        """ Used to explicitly initialiize the pyglass environment when running inside the source
            code respository with a standard structure where the repository root has a src and
            a resources folder. """

        if cls.isInitialized and not force:
            return True

        path = FileUtils.cleanupPath(referencePath, noTail=True)
        if os.path.isfile(path):
            path = FileUtils.getDirectoryOf(referencePath, noTail=True)

        rootPath = None
        while path:
            srcPath = FileUtils.makeFolderPath(path, 'src', isDir=True)
            resPath = FileUtils.makeFolderPath(path, 'resources', isDir=True)
            if os.path.exists(srcPath) and os.path.exists(resPath):
                rootPath = path
                break
            path = FileUtils.getDirectoryOf(path, noTail=True)

        if not rootPath:
            return False

        cls._rootResourcePath       = FileUtils.makeFolderPath(rootPath, 'resources')
        cls._rootLocalResourcePath  = FileUtils.makeFolderPath(rootPath, 'resources', 'local')
        return True
Ejemplo n.º 2
0
def initialize():
    path = FileUtils.makeFolderPath(MY_DIR, 'data')
    SystemUtils.remove(path)
    os.makedirs(path)

    tracks = DataLoadUtils.getTrackWithAnalysis()
    return tracks[['uid', 'site', 'width', 'sizeClass']]
Ejemplo n.º 3
0
    def tempPath(self):
        """ The root folder path where all temporary files created during analysis should be stored.
            This path is created on demand and always removed at the end of the analysis process,
            even if the process is aborted by an error in an analysis stage. """

        if not self._tempPath:
            return FileUtils.makeFolderPath(self._defaultRootPath, 'temp')
        return self._tempPath
Ejemplo n.º 4
0
def initialize(my_path):
    if os.path.isfile(my_path):
        my_path = FileUtils.getDirectoryOf(my_path)

    path = FileUtils.makeFolderPath(my_path, 'data')
    SystemUtils.remove(path)
    os.makedirs(path)

    return path
Ejemplo n.º 5
0
    def getAppDatabaseItems(cls, appName, localResourcesPath =None):
        if not localResourcesPath:
            localResourcesPath = PyGlassEnvironment.getRootLocalResourcePath(isDir=True)

        databaseRoot = FileUtils.makeFolderPath(localResourcesPath, 'apps', appName, 'data')
        if not os.path.exists(databaseRoot):
            return []

        results = []
        FileUtils.walkPath(databaseRoot, cls._findAppDatabases, {
            'root':databaseRoot,
            'results':results,
            'appName':appName })

        return results
Ejemplo n.º 6
0
    def getMigrationPathFromDatabaseUrl(cls, databaseUrl, root=False, resourcesPath=None):
        urlParts = databaseUrl.split("://")
        if urlParts[0].lower() == "shared":
            path = ["shared", "alembic"]
        else:
            path = ["apps", urlParts[0], "alembic"]

        if not root:
            path += urlParts[-1].split("/")

            # Remove the extension
            if path[-1].endswith(".vdb"):
                path[-1] = path[-1][:-4]

        if resourcesPath:
            return FileUtils.makeFolderPath(resourcesPath, *path, isDir=True)

        return PyGlassEnvironment.getRootResourcePath(*path, isDir=True)
Ejemplo n.º 7
0
    def hasMigrationEnvironment(cls, databaseUrl, resourcesPath =None):
        """ Determines whether or not the specified application database currently has a migration
            environment setup
            :param databaseUrl:
            :param resourcesPath:
            :return: True or false depending on the presence of a migration environment """

        if not resourcesPath:
            resourcesPath = PyGlassEnvironment.getRootResourcePath(isDir=True)

        migrationPath = PyGlassModelUtils.getMigrationPathFromDatabaseUrl(
            databaseUrl=databaseUrl, resourcesPath=resourcesPath)

        if not os.path.exists(migrationPath):
            return False
        if not os.path.exists(FileUtils.makeFilePath(migrationPath, 'alembic.ini')):
            return False
        if not os.path.exists(FileUtils.makeFolderPath(migrationPath, 'versions')):
            return False
        return True
Ejemplo n.º 8
0
from __future__ import print_function, absolute_import, unicode_literals, division

import os
import sys

from pyaid.file.FileUtils import FileUtils
from pyaid.json.JSON import JSON
from pyaid.system.SystemUtils import SystemUtils

FOLDER_NAME = 'Statistical-Results'

#---------------------------------------------------------------------------------------------------

rootPath = FileUtils.getDirectoryOf(__file__)
localAnalysisPath = FileUtils.makeFolderPath(rootPath, '..', 'resources', 'local', 'analysis')
analysisConfigPath = FileUtils.makeFilePath(localAnalysisPath, 'analysis.json')

config = JSON.fromFile(analysisConfigPath)

if 'OUTPUT_PATH' not in config:
    rootTargetPath = localAnalysisPath
else:
    rootTargetPath = FileUtils.cleanupPath(config['OUTPUT_PATH'], isDir=True)

targetPath = FileUtils.makeFolderPath(rootTargetPath, FOLDER_NAME)

if os.path.exists(targetPath):
    SystemUtils.remove(targetPath)

outputPath = FileUtils.makeFolderPath(rootPath, 'output')
Ejemplo n.º 9
0
import locale
import numpy as np
import pandas as pd
import plotly.graph_objs as plotlyGraph
from cadence.analysis.shared import DataLoadUtils, PlotConfigs
from cadence.analysis.shared.plotting import PlotlyUtils
from plotly import plotly

################################################################################

locale.setlocale(locale.LC_ALL, ('en_US', 'utf8'))

PLOTLY_FOLDER = 'Comparison'

MY_DIR = FileUtils.getDirectoryOf(__file__)
DATA_DIR = FileUtils.makeFolderPath(MY_DIR, 'data')
OUT_PATH = FileUtils.makeFilePath(DATA_DIR, 'deviation.h5')
METADATA_FILE = FileUtils.makeFilePath(DATA_DIR, 'deviation.metadata.json')

#_______________________________________________________________________________
def _getLayout(
        metadata, title, fixed = False, xAxis =None, yAxis =None, **kwargs
):
    if not xAxis:
        xAxis = {}
    xAxis.setdefault('title', 'Deviation (%)')

    if not yAxis:
        yAxis = {}
    yAxis.setdefault('title', 'Frequency')
    yAxis.setdefault('autorange', True)
Ejemplo n.º 10
0
 def currentLocalAppResourcesPath(self):
     if not self.currentAppPath:
         return None
     return FileUtils.makeFolderPath(self.currentAppPath, 'resources', 'local', isDir=True)
Ejemplo n.º 11
0
# (C)2015
# Scott Ernst

from __future__ import \
    print_function, absolute_import, \
    unicode_literals, division

import os
import re

import sqlalchemy as sqla
import pandas as pd

from pyaid.file.FileUtils import FileUtils

ROOT_PROJECT_PATH = FileUtils.makeFolderPath(
    FileUtils.getDirectoryOf(__file__), '..', '..')

_data = None

#_______________________________________________________________________________
def getProjectPath(*args, **kwargs):
    """ Creates an absolute path from the relative path arguments within the
        project folder.
    """
    return FileUtils.createPath(ROOT_PROJECT_PATH, *args, **kwargs)

#_______________________________________________________________________________
def getResourcesPath(*args, **kwargs):
    """ Creates an absolute path from the relative path arguments within the
        project folder.
    """
Ejemplo n.º 12
0
from __future__ import print_function
from __future__ import unicode_literals

from collections import namedtuple

from pyaid.file.CsvWriter import CsvWriter
from pyaid.file.FileUtils import FileUtils

import six
from cadence import reporting
from cadence.analysis.shared import DataLoadUtils
from cadence.enums.TrackCsvColumnEnum import TrackCsvColumnEnum
from cadence.enums.TrackPropEnum import TrackPropEnum

MY_DIR = FileUtils.getDirectoryOf(__file__)
DATA_DIR = FileUtils.makeFolderPath(MY_DIR, "data")
OUT_PATH = FileUtils.makeFilePath(DATA_DIR, "beb500.h5")
METADATA_FILE = FileUtils.makeFilePath(DATA_DIR, "beb500.metadata.json")

TCCE = TrackCsvColumnEnum
TPE = TrackPropEnum

ENTRY = namedtuple("ENTRY", ["label", "src", "dest"])

CONVERSIONS = [
    ENTRY("Index", TCCE.INDEX, None),
    ENTRY("Tracksite", TCCE.TRACKSITE, TPE.SITE),
    ENTRY("Level", TCCE.LEVEL, TPE.LEVEL),
    ENTRY("Trackway", TCCE.TRACKWAY, None),
    ENTRY("Excavation Area", TCCE.SECTOR, TPE.SECTOR),
    ENTRY("E", TCCE.ENTRY_AZIMUTH, ""),
Ejemplo n.º 13
0
    def outputRootPath(self):
        """ The root folder where analysis output files for this particular Analyzer should be
            stored. This path represents a folder within the analysisRootPath property specific
            to this analyzer. """

        return FileUtils.makeFolderPath(self.analysisRootPath, self.__class__.__name__)