<commit_before>import numpy as np
import json
import re
from genologics.entities import *
from genologics.lims import Lims
from genologics.config import BASEURI, USERNAME, PASSWORD
from datetime import datetime, timedelta
from decimal import Decimal
lims = Lims(BASEURI, USERNAME, PASSWORD)


class ProjectViewsIter:
    """
        Constructs an iterator from statusDB views, using projectsDB/project/summary as base, ie.
        {
            summary.key:        P????
            summary.value1:     ..,
            summary.value2:     ..,
            ...,
            project_dates:      projectsDB/project/summary_dates[summary.key],
            project_samples:    projectsDB/project/samples[summary.key],
            worksets:           worksetsDB/project/ws_proj[summary.key]
        }
    """
    def __init__(self, project_summary, project_samples, project_dates, worksets_proj, ofptype=None):
        self.proj_key = None
        self.value = None
        self.ofptype = ofptype
        self.summary_iter = iter(project_summary.rows)
        self.project_samples = project_samples
        self.project_dates = project_dates
        self.worksets_proj = worksets_proj

    def __iter__(self):
        return self

    def next(self):
        tmp = self.summary_iter.next()
        if self.ofptype is not None:
            while True:
                test_ptype = tmp.get("value", {}).get("details", {}).get("type")
                if test_ptype == self.ofptype:
                    break
                tmp = self.summary_iter.next()
        
        self.proj_key = tmp["key"][1]
        self.value = tmp.get("value", {})             

        try:
            self.value["project_dates"] = self.project_dates[[self.proj_key]].rows[0]["value"]
        except:
            pass

        try:
            samples = self.project_samples[self.proj_key]
            self.value["project_samples"] = samples.rows[0]["value"]
        except:
            pass

        try:
            self.value["worksets"] = {}
            for row in self.worksets_proj[self.proj_key].rows:
                self.value["worksets"].update(row.value)
        except:
            pass

        return (self.proj_key, self.value)


def estimate_lanes_per_artifact(art):
    lanes=0
    for sample in art.samples:
        try:
            lanes+=float(sample.project.udf['Sequence units ordered (lanes)']) / lims.get_sample_number(projectlimsid=sample.project.id)
        except:
            pass

    return round(Decimal(lanes), 2)

def sequencing_load():

    #This handles the QUEUES only
    q_miseq_s_ids=['52', '53', '54', '505']
    q_miseq_p_ids=['55', '56', '253', '1002']
    q_hiseq_s_ids=['252', '46', '47', '401']
    q_hiseq_p_ids=['49', '125', '1001', '50']
    q_hiseqX_s_ids=['751', '711', '712']
    q_hiseqX_p_ids=['713', '714', '715', '716']
    miseq_s=0
    miseq_p=0
    miseq_l=0
    hiseq_s=0
    hiseq_p=0
    hiseq_l=0
    hiseqX_s=0
    hiseqX_p=0
    hiseqX_l=0
    for s in q_miseq_s_ids:
        q=Queue(lims, id=s)
        miseq_s+=len(q.artifacts)
        for art in q.artifacts:
            miseq_l+=estimate_lanes_per_artifact(art)
    for s in q_miseq_p_ids:
        q=Queue(lims, id=s)
        miseq_p+=len(q.artifacts)
        for art in q.artifacts:
            miseq_l+=estimate_lanes_per_artifact(art)
    for s in q_hiseq_s_ids:
        q=Queue(lims, id=s)
        hiseq_s+=len(q.artifacts)
        for art in q.artifacts:
            hiseq_l+=estimate_lanes_per_artifact(art)
    for s in q_hiseq_p_ids:
        q=Queue(lims, id=s)
        hiseq_p+=len(q.artifacts)
        for art in q.artifacts:
            hiseq_l+=estimate_lanes_per_artifact(art)
    for s in q_hiseqX_s_ids:
        q=Queue(lims, id=s)
        hiseqX_s+=len(q.artifacts)
        for art in q.artifacts:
            hiseqX_l+=estimate_lanes_per_artifact(art)
    for s in q_hiseqX_p_ids:
        q=Queue(lims, id=s)
        hiseqX_p+=len(q.artifacts)
        for art in q.artifacts:
            hiseqX_l+=estimate_lanes_per_artifact(art)
    #This handles what is currently running
    hiseq_rl=0
    hiseqx_rl=0
    miseq_rl=0
    starting_date=datetime.now() - timedelta(5)
    hiseq_pr=lims.get_processes(type="Illumina Sequencing (Illumina SBS) 4.0", last_modified=starting_date.strftime("%Y-%m-%dT%H:%M:%SZ"))
    for pro in hiseq_pr:
        if not pro.udf.get("Finish Date"):
            for art in pro.all_inputs():
                hiseq_rl+=estimate_lanes_per_artifact(art)
    hiseqx_pr=lims.get_processes(type="Illumina Sequencing (HiSeq X) 1.0", last_modified=starting_date.strftime("%Y-%m-%dT%H:%M:%SZ"))
    for pro in hiseqx_pr:
        if not pro.udf.get("Finish Date"):
            for art in pro.all_inputs():
                hiseqx_rl+=estimate_lanes_per_artifact(art)
    miseq_pr=lims.get_processes(type="MiSeq Run (MiSeq) 4.0", last_modified=starting_date.strftime("%Y-%m-%dT%H:%M:%SZ"))
    for pro in miseq_pr:
        if not pro.udf.get("Finish Date"):
            for art in pro.all_inputs():
                miseq_rl+=estimate_lanes_per_artifact(art)



    return [miseq_s, miseq_p, int(miseq_l), hiseq_s, hiseq_p, int(hiseq_l), hiseqX_s, hiseqX_p, int(hiseqX_l), int(hiseq_rl), int(hiseqx_rl), int(miseq_rl)]<commit_msg>changing how to see the lanes currently sequencing<commit_after>import numpy as np
import json
import re
from genologics.entities import *
from genologics.lims import Lims
from genologics.config import BASEURI, USERNAME, PASSWORD
from datetime import datetime, timedelta
from decimal import Decimal
lims = Lims(BASEURI, USERNAME, PASSWORD)


class ProjectViewsIter:
    """
        Constructs an iterator from statusDB views, using projectsDB/project/summary as base, ie.
        {
            summary.key:        P????
            summary.value1:     ..,
            summary.value2:     ..,
            ...,
            project_dates:      projectsDB/project/summary_dates[summary.key],
            project_samples:    projectsDB/project/samples[summary.key],
            worksets:           worksetsDB/project/ws_proj[summary.key]
        }
    """
    def __init__(self, project_summary, project_samples, project_dates, worksets_proj, ofptype=None):
        self.proj_key = None
        self.value = None
        self.ofptype = ofptype
        self.summary_iter = iter(project_summary.rows)
        self.project_samples = project_samples
        self.project_dates = project_dates
        self.worksets_proj = worksets_proj

    def __iter__(self):
        return self

    def next(self):
        tmp = self.summary_iter.next()
        if self.ofptype is not None:
            while True:
                test_ptype = tmp.get("value", {}).get("details", {}).get("type")
                if test_ptype == self.ofptype:
                    break
                tmp = self.summary_iter.next()
        
        self.proj_key = tmp["key"][1]
        self.value = tmp.get("value", {})             

        try:
            self.value["project_dates"] = self.project_dates[[self.proj_key]].rows[0]["value"]
        except:
            pass

        try:
            samples = self.project_samples[self.proj_key]
            self.value["project_samples"] = samples.rows[0]["value"]
        except:
            pass

        try:
            self.value["worksets"] = {}
            for row in self.worksets_proj[self.proj_key].rows:
                self.value["worksets"].update(row.value)
        except:
            pass

        return (self.proj_key, self.value)


def estimate_lanes_per_artifact(art):
    lanes=0
    for sample in art.samples:
        try:
            lanes+=float(sample.project.udf['Sequence units ordered (lanes)']) / lims.get_sample_number(projectlimsid=sample.project.id)
        except:
            pass

    return round(Decimal(lanes), 2)

def sequencing_load():

    #This handles the QUEUES only
    q_miseq_s_ids=['52', '53', '54', '505']
    q_miseq_p_ids=['55', '56', '253', '1002']
    q_hiseq_s_ids=['252', '46', '47', '401']
    q_hiseq_p_ids=['49', '125', '1001', '50']
    q_hiseqX_s_ids=['751', '711', '712']
    q_hiseqX_p_ids=['713', '714', '715', '716']
    miseq_s=0
    miseq_p=0
    miseq_l=0
    hiseq_s=0
    hiseq_p=0
    hiseq_l=0
    hiseqX_s=0
    hiseqX_p=0
    hiseqX_l=0
    for s in q_miseq_s_ids:
        q=Queue(lims, id=s)
        miseq_s+=len(q.artifacts)
        for art in q.artifacts:
            miseq_l+=estimate_lanes_per_artifact(art)
    for s in q_miseq_p_ids:
        q=Queue(lims, id=s)
        miseq_p+=len(q.artifacts)
        for art in q.artifacts:
            miseq_l+=estimate_lanes_per_artifact(art)
    for s in q_hiseq_s_ids:
        q=Queue(lims, id=s)
        hiseq_s+=len(q.artifacts)
        for art in q.artifacts:
            hiseq_l+=estimate_lanes_per_artifact(art)
    for s in q_hiseq_p_ids:
        q=Queue(lims, id=s)
        hiseq_p+=len(q.artifacts)
        for art in q.artifacts:
            hiseq_l+=estimate_lanes_per_artifact(art)
    for s in q_hiseqX_s_ids:
        q=Queue(lims, id=s)
        hiseqX_s+=len(q.artifacts)
        for art in q.artifacts:
            hiseqX_l+=estimate_lanes_per_artifact(art)
    for s in q_hiseqX_p_ids:
        q=Queue(lims, id=s)
        hiseqX_p+=len(q.artifacts)
        for art in q.artifacts:
            hiseqX_l+=estimate_lanes_per_artifact(art)
    #This handles what is currently running
    hiseq_rl=0
    hiseqx_rl=0
    miseq_rl=0
    starting_date=datetime.now() - timedelta(5)
    hiseq_pr=lims.get_processes(type="Illumina Sequencing (Illumina SBS) 4.0", last_modified=starting_date.strftime("%Y-%m-%dT%H:%M:%SZ"))
    for pro in hiseq_pr:
        if not pro.udf.get("Finish Date"):
            hiseq_rl+=len(pro.all_outputs())
    hiseqx_pr=lims.get_processes(type="Illumina Sequencing (HiSeq X) 1.0", last_modified=starting_date.strftime("%Y-%m-%dT%H:%M:%SZ"))
    for pro in hiseqx_pr:
        if not pro.udf.get("Finish Date"):
            hiseqx_rl+=len(pro.all_outputs())
    miseq_pr=lims.get_processes(type="MiSeq Run (MiSeq) 4.0", last_modified=starting_date.strftime("%Y-%m-%dT%H:%M:%SZ"))
    for pro in miseq_pr:
        if not pro.udf.get("Finish Date"):
            miseq_rl+=len(pro.all_outputs())



    return [miseq_s, miseq_p, int(miseq_l), hiseq_s, hiseq_p, int(hiseq_l), hiseqX_s, hiseqX_p, int(hiseqX_l), int(hiseq_rl), int(hiseqx_rl), int(miseq_rl)]
{'fraction_non_alphanumeric': 0.11969521604938271, 'fraction_numerical': 0.016975308641975308, 'mean_word_length': 2.4448504983388704, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4133165', 'n_tokens_mistral': 3867, 'n_tokens_neox': 3728, 'n_words': 674}