示例#1
0
    def main():
        from pychron.paths import paths
        paths.build('_dev')
        from pychron.core.helpers.logger_setup import logging_setup
        from pychron.experiment.automated_run.spec import AutomatedRunSpec
        logging_setup('dvcdb')
        from pychron.dvc.dvc_database import DVCDatabase
        from itertools import groupby
        db = DVCDatabase(kind='mysql', host='localhost', username='******', name='pychronmeta', password='******')
        db.connect()
        identifiers = ['63290', '63291']
        runs = [AutomatedRunSpec(identifier='63290', repository_identifier='Cather_McIntoshd')]
        cr = ConflictResolver()
        experiments = {}
        cr.available_ids = db.get_repository_identifiers()
        eas = db.get_associated_repositories(identifiers)
        for idn, exps in groupby(eas, key=lambda x: x[1]):
            experiments[idn] = [e[0] for e in exps]
        conflicts = []
        for ai in runs:
            identifier = ai.identifier
            es = experiments[identifier]
            if ai.repository_identifier not in es:
                conflicts.append((ai, es))
        if conflicts:
            cr.add_conflicts('Foo', conflicts)

        if cr.conflicts:

            info = cr.edit_traits(kind='livemodal')
            if info.result:
                cr.apply()
示例#2
0
    def main():
        from pychron.paths import paths
        paths.build('_dev')
        from pychron.core.helpers.logger_setup import logging_setup
        from pychron.experiment.automated_run.spec import AutomatedRunSpec
        logging_setup('dvcdb')
        from pychron.dvc.dvc_database import DVCDatabase
        from itertools import groupby
        db = DVCDatabase(kind='mysql',
                         host='localhost',
                         username='******',
                         name='pychronmeta',
                         password='******')
        db.connect()
        identifiers = ['63290', '63291']
        runs = [
            AutomatedRunSpec(identifier='63290',
                             repository_identifier='Cather_McIntoshd')
        ]
        cr = ConflictResolver()
        experiments = {}
        with db.session_ctx():
            cr.available_ids = db.get_repository_identifiers()
            eas = db.get_associated_repositories(identifiers)
            for idn, exps in groupby(eas, key=lambda x: x[1]):
                experiments[idn] = [e[0] for e in exps]
            conflicts = []
            for ai in runs:
                identifier = ai.identifier
                es = experiments[identifier]
                if ai.repository_identifier not in es:
                    conflicts.append((ai, es))
            if conflicts:
                cr.add_conflicts('Foo', conflicts)

        if cr.conflicts:

            info = cr.edit_traits(kind='livemodal')
            if info.result:
                cr.apply()
示例#3
0
            if prog:
                # if prog and i % 25 == 0:
                prog.change_message('Loading {}'.format(xi.record_id))
            return xi

        return progress_loader(ans, func, threshold=25, step=25)

    def _load_entries(self):
        p = paths.hidden_path('search_entries')
        if os.path.isfile(p):
            with open(p, 'r') as rfile:
                self.search_entries = yaml.load(rfile)

    def _search_entry_changed(self):
        self.search()


if __name__ == '__main__':
    db = DVCDatabase(bind=False, kind='mysql', host='localhost', username='******', name='pychrondvc_dev',
                     password='******')
    db.connect()

    # s = SearchParser(db=db)
    # s.parse('s:FC-2')
    # s.parse('s:=FC-2')
    # s.parse('s=FC-2')
    s = Searcher(db=db)
    s.search_entry = 's:FC-2'
    s.search()
# ============= EOF =============================================
示例#4
0
        dlg = FileDialog(action='open', default_directory=paths.irradiation_tray_maps_dir)
        if dlg.open() == OK:
            if dlg.path:
                # verify this is a valid irradiation map file
                if parse_irradiation_tray_map(dlg.path) is not None:
                    db = self.db
                    load_irradiation_map(db, dlg.path,
                                         os.path.basename(dlg.path), overwrite_geometry=True)


if __name__ == '__main__':
    paths.build('_dev')
    logging_setup('le')
    from pychron.dvc.dvc_database import DVCDatabase

    dbt = DVCDatabase(kind='sqlite', path='/Users/ross/Programming/test3.sqlite')
    dbt.connect()
    # from pychron.dvc.meta_repo import MetaRepo

    mr = MetaRepo()
    mr.open_repo(paths.meta_root)


    class Demo(HasTraits):
        test = Button
        traits_view = View('test')

        def _test_fired(self):
            e = LevelEditor(db=dbt,
                            meta_repo=mr,
                            irradiation='NM-274',
示例#5
0
                # verify this is a valid irradiation map file
                if parse_irradiation_tray_map(dlg.path) is not None:
                    db = self.db
                    with db.session_ctx():
                        load_irradiation_map(db,
                                             dlg.path,
                                             os.path.basename(dlg.path),
                                             overwrite_geometry=True)


if __name__ == '__main__':
    paths.build('_dev')
    logging_setup('le')
    from pychron.dvc.dvc_database import DVCDatabase

    dbt = DVCDatabase(kind='sqlite',
                      path='/Users/ross/Programming/test3.sqlite')
    dbt.connect()
    # from pychron.dvc.meta_repo import MetaRepo

    mr = MetaRepo()
    mr.open_repo(paths.meta_root)

    class Demo(HasTraits):
        test = Button
        traits_view = View('test')

        def _test_fired(self):
            e = LevelEditor(db=dbt,
                            meta_repo=mr,
                            irradiation='NM-274',
                            name='H')
示例#6
0
                attr = getattr(tbl, attr)

                if ',' in val:
                    f = attr.in_(val.split('.'))
                else:
                    f = attr == val
                filters.append(f)
            else:
                print('invalid table {}'.format(tbl))

        return filters


if __name__ == '__main__':
    db = DVCDatabase(
        host='localhost',
        username=os.environ.get('LOCALHOST_DB_USER'),
        password=os.environ.get('LOCALHOST_DB_PWD'),
        kind='mysql',
        # echo=True,
        name='pychrondvc_dev')
    txt = '''project.name: Irradiation-NM-274
sample: FC-2'''
    # txt = '''sample: FC-2'''
    db.connect()
    c = CustomAnalysisQuery(db=db)
    q = c.generate_query(txt)
    c.execute_query(q)

# ============= EOF =============================================
示例#7
0
    def _clone_central_db(self,
                          repositories,
                          analyses=None,
                          principal_investigators=None,
                          projects=None):

        self.info('--------- Clone DB -----------')
        # create an a sqlite database
        from pychron.dvc.dvc_orm import Base
        metadata = Base.metadata
        from pychron.dvc.dvc_database import DVCDatabase

        path = database_path()
        if os.path.isfile(path):
            if not self.confirmation_dialog(
                    'The database "{}" already exists. '
                    'Do you want to overwrite it'.format(
                        os.path.basename(path))):

                path = self._get_new_path()
            else:
                os.remove(path)

        if path:
            progress = open_progress(n=20)
            self.debug('--------- Starting db clone to {}'.format(path))
            src = self.dvc
            db = DVCDatabase(path=path, kind='sqlite')
            db.connect()
            with db.session_ctx(use_parent_session=False) as sess:
                metadata.create_all(sess.bind)

            tables = [
                'MassSpectrometerTbl', 'ExtractDeviceTbl', 'VersionTbl',
                'UserTbl'
            ]

            for table in tables:
                mod = __import__('pychron.dvc.dvc_orm', fromlist=[table])
                progress.change_message('Cloning {}'.format(table))
                self._copy_table(db, getattr(mod, table))

            with src.session_ctx(use_parent_session=False):
                from pychron.dvc.dvc_orm import RepositoryTbl
                from pychron.dvc.dvc_orm import AnalysisTbl
                from pychron.dvc.dvc_orm import AnalysisChangeTbl
                from pychron.dvc.dvc_orm import RepositoryAssociationTbl
                from pychron.dvc.dvc_orm import AnalysisGroupTbl
                from pychron.dvc.dvc_orm import AnalysisGroupSetTbl
                from pychron.dvc.dvc_orm import MaterialTbl
                from pychron.dvc.dvc_orm import SampleTbl
                from pychron.dvc.dvc_orm import IrradiationTbl
                from pychron.dvc.dvc_orm import LevelTbl
                from pychron.dvc.dvc_orm import IrradiationPositionTbl
                from pychron.dvc.dvc_orm import PrincipalInvestigatorTbl

                repos = [
                    src.db.get_repository(reponame)
                    for reponame in repositories
                ]

                progress.change_message('Assembling Analyses 0/5')
                st = time.time()
                if analyses:
                    ans = analyses
                    ras = [
                        rai for ai in ans for rai in ai.repository_associations
                    ]
                else:

                    # at = time.time()
                    ras = [
                        ra for repo in repos
                        for ra in repo.repository_associations
                    ]
                    # self.debug('association time={}'.format(time.time()-at))
                    progress.change_message('Assembling Analyses 1/5')

                    # at = time.time()
                    ans = [ri.analysis for ri in ras]
                    # self.debug('analysis time={}'.format(time.time()-at))

                    progress.change_message('Assembling Analyses 2/5')

                # at = time.time()
                ans_c = [ai.change for ai in ans]
                # self.debug('change time={}'.format(time.time()-at))
                progress.change_message('Assembling Analyses 3/5')

                # at = time.time()
                agss = [gi for ai in ans for gi in ai.group_sets]
                # self.debug('agss time={}'.format(time.time()-at))
                progress.change_message('Assembling Analyses 4/5')

                # at = time.time()
                ags = {gi.group for gi in agss}
                # self.debug('ags time={}'.format(time.time()-at))
                progress.change_message('Assembling Analyses 5/5')

                self.debug(
                    'total analysis assembly time={}'.format(time.time() - st))

                self._copy_records(progress, db, RepositoryTbl, repos)
                self._copy_records(progress, db, RepositoryAssociationTbl, ras)
                self._copy_records(progress, db, AnalysisTbl, ans)
                self._copy_records(progress, db, AnalysisChangeTbl, ans_c)
                self._copy_records(progress, db, AnalysisGroupTbl, ags)
                self._copy_records(progress, db, AnalysisGroupSetTbl, agss)

                if principal_investigators:
                    pis = [
                        src.get_principal_investigator(pp.name)
                        for pp in principal_investigators
                    ]
                else:
                    pis = {repo.principal_investigator for repo in repos}
                self._copy_records(progress, db, PrincipalInvestigatorTbl, pis)

                from pychron.dvc.dvc_orm import ProjectTbl
                if projects:
                    prjs = [src.get_project(pp) for pp in projects]
                else:
                    prjs = {
                        ai.irradiation_position.sample.project
                        for ai in ans
                    }
                self._copy_records(progress, db, ProjectTbl, prjs)

                ips = {ai.irradiation_position for ai in ans}
                sams = {ip.sample for ip in ips}
                mats = {si.material for si in sams}

                self._copy_records(progress, db, MaterialTbl, mats)

                self._copy_records(progress, db, SampleTbl, sams)

                ls = {ip.level for ip in ips}
                irs = {l.irradiation for l in ls}

                self._copy_records(progress, db, IrradiationTbl, irs)

                self._copy_records(progress, db, LevelTbl, ls)

                self._copy_records(progress, db, IrradiationPositionTbl, ips)

                self.debug('--------- db clone finished')
                progress.close()
                self.information_dialog('Database saved to "{}"'.format(path))
                return path
示例#8
0
    def _clone_central_db(self, repositories, analyses=None, principal_investigators=None, projects=None):

        self.info('--------- Clone DB -----------')
        # create an a sqlite database
        from pychron.dvc.dvc_orm import Base
        metadata = Base.metadata
        from pychron.dvc.dvc_database import DVCDatabase

        path = database_path()
        if os.path.isfile(path):
            if not self.confirmation_dialog('The database "{}" already exists. '
                                            'Do you want to overwrite it'.format(os.path.basename(path))):

                path = self._get_new_path()
            else:
                os.remove(path)

        if path:
            progress = open_progress(n=20)
            self.debug('--------- Starting db clone to {}'.format(path))
            src = self.dvc
            db = DVCDatabase(path=path, kind='sqlite')
            db.connect()
            with db.session_ctx(use_parent_session=False) as sess:
                metadata.create_all(sess.bind)

            tables = ['MassSpectrometerTbl', 'ExtractDeviceTbl', 'VersionTbl', 'UserTbl']

            for table in tables:
                mod = __import__('pychron.dvc.dvc_orm', fromlist=[table])
                progress.change_message('Cloning {}'.format(table))
                self._copy_table(db, getattr(mod, table))

            with src.session_ctx(use_parent_session=False):
                from pychron.dvc.dvc_orm import RepositoryTbl
                from pychron.dvc.dvc_orm import AnalysisTbl
                from pychron.dvc.dvc_orm import AnalysisChangeTbl
                from pychron.dvc.dvc_orm import RepositoryAssociationTbl
                from pychron.dvc.dvc_orm import AnalysisGroupTbl
                from pychron.dvc.dvc_orm import AnalysisGroupSetTbl
                from pychron.dvc.dvc_orm import MaterialTbl
                from pychron.dvc.dvc_orm import SampleTbl
                from pychron.dvc.dvc_orm import IrradiationTbl
                from pychron.dvc.dvc_orm import LevelTbl
                from pychron.dvc.dvc_orm import IrradiationPositionTbl
                from pychron.dvc.dvc_orm import PrincipalInvestigatorTbl

                repos = [src.db.get_repository(reponame) for reponame in repositories]

                progress.change_message('Assembling Analyses 0/5')
                st = time.time()
                if analyses:
                    ans = analyses
                    ras = [rai for ai in ans
                           for rai in ai.repository_associations]
                else:

                    # at = time.time()
                    ras = [ra for repo in repos for ra in repo.repository_associations]
                    # self.debug('association time={}'.format(time.time()-at))
                    progress.change_message('Assembling Analyses 1/5')

                    # at = time.time()
                    ans = [ri.analysis for ri in ras]
                    # self.debug('analysis time={}'.format(time.time()-at))

                    progress.change_message('Assembling Analyses 2/5')

                # at = time.time()
                ans_c = [ai.change for ai in ans]
                # self.debug('change time={}'.format(time.time()-at))
                progress.change_message('Assembling Analyses 3/5')

                # at = time.time()
                agss = [gi for ai in ans for gi in ai.group_sets]
                # self.debug('agss time={}'.format(time.time()-at))
                progress.change_message('Assembling Analyses 4/5')

                # at = time.time()
                ags = {gi.group for gi in agss}
                # self.debug('ags time={}'.format(time.time()-at))
                progress.change_message('Assembling Analyses 5/5')

                self.debug('total analysis assembly time={}'.format(time.time()-st))

                self._copy_records(progress, db, RepositoryTbl, repos)
                self._copy_records(progress, db, RepositoryAssociationTbl, ras)
                self._copy_records(progress, db, AnalysisTbl, ans)
                self._copy_records(progress, db, AnalysisChangeTbl, ans_c)
                self._copy_records(progress, db, AnalysisGroupTbl, ags)
                self._copy_records(progress, db, AnalysisGroupSetTbl, agss)

                if principal_investigators:
                    pis = [src.get_principal_investigator(pp.name) for pp in principal_investigators]
                else:
                    pis = {repo.principal_investigator for repo in repos}
                self._copy_records(progress, db, PrincipalInvestigatorTbl, pis)

                from pychron.dvc.dvc_orm import ProjectTbl
                if projects:
                    prjs = [src.get_project(pp) for pp in projects]
                else:
                    prjs = {ai.irradiation_position.sample.project for ai in ans}
                self._copy_records(progress, db, ProjectTbl, prjs)

                ips = {ai.irradiation_position for ai in ans}
                sams = {ip.sample for ip in ips}
                mats = {si.material for si in sams}

                self._copy_records(progress, db, MaterialTbl, mats)

                self._copy_records(progress, db, SampleTbl, sams)

                ls = {ip.level for ip in ips}
                irs = {l.irradiation for l in ls}

                self._copy_records(progress, db, IrradiationTbl, irs)

                self._copy_records(progress, db, LevelTbl, ls)

                self._copy_records(progress, db, IrradiationPositionTbl, ips)

                self.debug('--------- db clone finished')
                progress.close()
                self.information_dialog('Database saved to "{}"'.format(path))
                return path
示例#9
0
 def _db_default(self):
     return DVCDatabase(kind='mysql',
                        username='******',
                        password='******',
                        host='localhost',
                        name='pychronmeta')