Esempio n. 1
0
    def _get_business_from_caseone(self, caseone):
        resp = {}
        exist_keys = self._get_business_names()
        setupId = caseone.get('SetupID', '')
        processId = caseone.get("ProcessID", [])
        teardownId = caseone.get('TeardownID', '')
        keys = list(filter(None, list(set(processId + [setupId, teardownId]))))
        import copy

        keys_copy = copy.deepcopy(keys)
        for key in keys_copy:
            if key in exist_keys:
                keys.remove(key)

        for key in keys:
            if key == setupId:
                doc = caseone.get("SetupDoc", "")
                param = ""
                resp.update({
                    key: {
                        'businessID': key,
                        "Documentation": doc,
                        "Params": param
                    }
                })

            if key == teardownId:
                doc = caseone.get("TeardownDoc", "")
                param = ""
                resp.update({
                    key: {
                        'businessID': key,
                        "Documentation": doc,
                        "Params": param
                    }
                })

            if key in processId:
                index = processId.index(key)
                doc = caseone.get("ProcessDoc", [])[index]
                param = caseone.get("Params", [])[index]
                resp.update({
                    key: {
                        'businessID': key,
                        "Documentation": doc,
                        "Params": param
                    }
                })
        return resp
Esempio n. 2
0
'copy.deepcopy(x)'
'''一般赋值中,是把变量指向某内存,当修改该变量时(除非是重新指向其他内存),
会影响到所指向的内存中的变量,赋值时,用deepcopy即可避免内存变量的变动'''
import copy
a = [1,2,3]
b = a
b[0] = 'modified'
print(a)
a1 = [2,3,4]
b1 = []
b1.append(a1)
b1[-1][0] = 'modified'
print(a1)
a2 = [6, 6, 6]
b2 = copy.deepcopy(a2)
b2[0] = 'modified'
print(a2)
'# 结束----------------------------'

'pcolor(xx,yy,zz)'
'''云图,xx,yy为二维数据,一般通过等间隔一维数组用Meshgrid产生,指示平面内每个点的横纵坐标,
zz和xx,yy形式相同,表示每个坐标点上的z值'''
x = numpy.arange(-2, 3, 1)
y = numpy.arange(-2, 3, 1)
xx, yy = numpy.meshgrid(x, y)
zz = xx + yy
qq=plt.pcolor(xx, yy,zz, cmap='jet')
'# 结束----------------------------'

'plt.pie'
Esempio n. 3
0
def vinicial(X1, X2, lv, y1, y2):

    X11 = copy.deepcopy(X1)
    X22 = copy.deepcopy(X2)
    X11 = np.append(X11, np.zeros(lv - len(X11) % lv))
    X22 = np.append(X22, np.zeros(lv - len(X22) % lv))
    l = len(X11) / lv

    rms1 = float(np.sqrt(np.mean(X11**2)))
    rms2 = float(np.sqrt(np.mean(X22**2)))
    X11 = X11 / rms1
    X22 = X22 / rms2

    X11 = X11[:l * lv]
    X111 = copy.deepcopy(X11)
    X22 = X22[:l * lv]
    nl = np.floor(np.log2(len(X11) / lv))  #Numero de loops

    cmax = np.zeros(2)
    cpos = np.zeros(2)
    Cposa = 0
    X2pos = 0  # Posicion inicial del segmento final de X2
    j = 0

    while j < nl:
        l2 = np.round(len(X111) / 2)

        for i in range(2):
            u1 = l2 * i
            u2 = u1 + l2
            X2C = X22[u1:u2]  # Corta la senal modificada en partes igualles
            Y = signal.correlate(
                X111, X2C, 'full', 'fft'
            )  # Correlacion entre senal modificada cortada y de referencia
            cmax[i] = float(
                max(Y) /
                float(len(Y)))  # Vector de valores maximos de correlacion
            s = len(Y) / 2
            cpos[i] = np.argmax(
                Y) - s  # Vector de posicion de valores maximos de correlacion

        Cposr = np.argmax(cmax)  # Maxima posicion relativa
        X2pos = Cposr * l2 + X2pos
        Cposa = int(cpos[Cposr]) + Cposa  # Maxima posicion absoluta
        X22 = X22[l2 * Cposr:l2 * (Cposr + 1)]
        # print Cposa

        mp = len(
            X11
        ) / 2 + Cposa - l2 / 2  # Posicion inicial del vector X111 con respecto a X11

        if mp >= 0:
            X111 = X11[mp:mp + l2]
        else:
            X111 = np.append(np.zeros(abs(mp)), X11[:l2 + mp])

        # c = signal.correlate(X111,X22,'full','fft')
        # print(np.argmax(c)-len(c)/2)

        j += 1

    n = mp - X2pos

    if n < 0:
        z = np.zeros(abs(n))
        X1 = np.append(z, X1)
        y1 = np.append(z, y1)
        X2 = np.append(X2, z)
        y2 = np.append(y2, z)
        r = X2pos
    elif n > 0:
        z = np.zeros(abs(n))
        X2 = np.append(z, X2)
        y2 = np.append(z, y2)
        X1 = np.append(X1, z)
        y1 = np.append(y1, z)
        r = mp

    return X1, X2, r, y1, y2
Esempio n. 4
0
def cor2(X1, X2, lv, p, g, mv, fs, CCM, u):
    """
	Correlacion cruzada de audios.
	lv es la longitud de la ventana temporal a utilizar. 
	p es el porcentaje de lv donde transiciona entre 0 y 1.
	g es el umbral del gate
	mv es la maxima velocidad de desplazamiento entre microfonos
	fs es la frecuencia de muestreo
	CCM es el coeficiente de correlacion minima
	"""

    X11 = copy.deepcopy(X1)
    X12 = copy.deepcopy(X2)
    X11 = np.append(X11, np.zeros(lv - len(X11) % lv))
    X12 = np.append(X12, np.zeros(lv - len(X12) % lv))

    ################## Ventana temporal #########################
    w = np.blackman(round(lv * p))  # Genera la ventana blackman
    w1 = np.append(w[:len(w) / 2], np.ones(int(round(lv * (1 - p)))))
    w1 = np.append(w1,
                   w[len(w) / 2:])  # Crea la ventana temporal de longitud lv

    ################## Generacion de arrays del bucle for #######
    l = int(len(X11) / float(lv))  # Cantidad de ventanas temporales/ cilos for
    ta = np.zeros(l)  # Vector de corrimentos absolutos
    CC = np.zeros(l)  # Vector de maximas correlaciones por ventana
    M = np.ones(
        l)  # Vector de coeficientes de correccion por umbral de amplitud
    N = np.ones(
        l)  # Vector de coeficientes de correccion por umbral de correlacion

    ################## Maximo Corrimiento Posible ###############
    h = 2.0  # Multiplicador del maximo corrimiento
    mcs = math.ceil(fs * mv /
                    343.0)  # Maximo corrimiento en muestras por segundo
    mcv = int(math.ceil(lv * mcs / fs) *
              h)  # Maximo corrimiento en muestras por ventana
    mcvl = int(math.ceil(mcv / 2.0))  # Maximo corrimiento lateral

    ################## Parametros del bucle #####################
    m = 3  # Coeficiente de correccion por umbral de amplitud
    mm = 5  # Maximo valor de m
    n = 10  # Coeficiente de correccion por umbral de correlacion
    nm = 5  # Maximo valor de n
    tt = 0  # Parametro de ajuste para la correlacion
    rms1 = float(np.sqrt(np.mean(X11**2)))  # Valor rms de la senal X11
    rms2 = float(np.sqrt(np.mean(X12**2)))  # Valor rms de la senal X12

    ################## Bucle de correlacion #####################

    z = np.arange(u / lv - 1, -1, -1)
    t0 = np.zeros(len(z))  # Vector de corrimientos relativos a i-1
    for i in z:  # Calculo de corrimientos a la izquierda de la ventana inicial
        lv1 = int(lv * i)  # Limite inferior
        lv2 = int(lv * (i + 1))  # Limite superior
        Y1 = X11[lv1:lv2] * w1  # Senal de referencia ventaneada en tiempo
        RMS1 = float(np.sqrt(np.mean(
            Y1**2)))  # Valor RMS de la ventana de referencia
        Y1 = Y1 / RMS1  # Senal de referencia normalizada a su valor RMS

        if RMS1 / rms1 > g:  # Gate de la senal de referencia
            r = int(np.ceil(
                mcvl * m *
                n))  # Cantidad de muestras del corrimiento lateral por ventana
            c = np.zeros(int(np.ceil(mcv * m * n) +
                             1))  # Vector de correlaciones por ciclo del bucle

            for j in range(-r, r + 1):  # Ventaneo de la senal desplazada

                if i == 0 and j < 0:  # Condicion inicial de corrimiento hacia la izquierda
                    Y2 = np.append(np.zeros(abs(j)),
                                   X12[:int(lv2 + j)]) * w1  # Ventana Y2
                    RMS2 = float(np.sqrt(np.mean(Y2**2)))  # Valor RMS de Y2
                    Y2 = Y2 / RMS2  # Y2 Normalizada a su valor RMS

                elif i == 0 and j >= 0:  # Condicion inicial de corrimiento hacia la derecha
                    Y2 = X12[j:int(lv2 + j)] * w1  # Ventana Y2
                    RMS2 = float(np.sqrt(np.mean(Y2**2)))  # Valor RMS de Y2
                    Y2 = Y2 / RMS2  # Y2 Normalizada a su valor RMS

                elif len(X12[int(lv1 - tt -
                                 j):int(lv2 - tt -
                                        j)]) == lv:  # Condicion normal
                    Y2 = X12[int(lv1 - tt - j):int(lv2 - tt -
                                                   j)] * w1  # Ventana Y2
                    RMS2 = float(np.sqrt(np.mean(
                        Y2**2)))  # Valor cuadratico medio de Y2
                    Y2 = Y2 / RMS2  # Y2 Normalizada a su valor RMS

                else:
                    T = len(X12[int(lv1 - tt - j):int(lv2 - tt -
                                                      j)])  # Ultima ventana
                    TT = np.append(X12[int(lv1 - tt - j):int(lv2 - tt - j)],
                                   np.zeros(lv - T))  # Ventana Y2
                    Y2 = TT * w1
                    RMS2 = float(np.sqrt(np.mean(
                        Y2**2)))  # Valor cuadratico medio de Y2
                    Y2 = Y2 / float(RMS2)  # Y2 Normalizada a su valor RMS

                if RMS2 / rms2 > g:  # Gate de la senal desplazada
                    m = 1  # Reset del coeficiente de corrimiento maximo por amplitud
                    c[j + r] = signal.correlate(
                        Y1, Y2, 'valid', 'fft')  # Correlacion de senales
                    C = max(c) / float(lv)  # Valor de correlacion maxima

                    if C >= CCM:  # Condicion para valores de correlacion por debajo del umbral CCM
                        cm = np.argmax(
                            c) - r  # Posicion del valor de maxima correlacion
                        t0[i] = cm
                        n = 1  # Reset del coeficiente de corrimiento maximo por correlacion
                        CC[i] = C  # Vector de valores maximos de correlacion

                    else:
                        cm = 0
                        CC[i] = CCM

                        if n < nm:
                            n += 1

                    N[i] = n  # Vector de coeficientes de correccion por umbral de correlacion

                else:
                    t0[i] = 0

                    if m < mm:
                        m += 1
        else:
            t0[i] = 0

            if m < mm:
                m += 1

        M[i] = m  # Vector de coeficientes de correccion por umbral de amplitud

        ####### Vectores de corrimientos tt y ta ########
        tt = sum(t0)
        ta[i] = tt

    t1 = np.zeros(2 + l - u / lv)  # Vector de corrimientos relativos a i-1
    m = 1  # Coeficiente de correccion por umbral de amplitud
    n = 10  # Coeficiente de correccion por umbral de correlacion
    tt = 0  # Parametro de ajuste para la correlacion
    z = np.arange(u / lv, l)

    for i in z:
        lv1 = int(lv * i)  # Limite inferior
        lv2 = int(lv * (i + 1))  # Limite superior
        Y1 = X11[lv1:lv2] * w1  # Senal de referencia ventaneada en tiempo
        RMS1 = float(np.sqrt(np.mean(
            Y1**2)))  # Valor RMS de la ventana de referencia
        Y1 = Y1 / RMS1  # Senal de referencia normalizada a su valor RMS

        if RMS1 / rms1 > g:  # Gate de la senal de referencia
            r = int(np.ceil(
                mcvl * m *
                n))  # Cantidad de muestras del corrimiento lateral por ventana
            c = np.zeros(int(np.ceil(mcv * m * n) +
                             1))  # Vector de correlaciones por ciclo del bucle

            for j in range(-r, r + 1):  # Ventaneo de la senal desplazada
                if i == 0 and j < 0:  # Condicion inicial de corrimiento hacia la izquierda
                    Y2 = np.append(np.zeros(abs(j)),
                                   X12[:int(lv2 + j)]) * w1  # Ventana Y2
                    RMS2 = float(np.sqrt(np.mean(Y2**2)))  # Valor RMS de Y2
                    Y2 = Y2 / RMS2  # Y2 Normalizada a su valor RMS

                elif i == 0 and j >= 0:  # Condicion inicial de corrimiento hacia la derecha
                    Y2 = X12[j:int(lv2 + j)] * w1  # Ventana Y2
                    RMS2 = float(np.sqrt(np.mean(Y2**2)))  # Valor RMS de Y2
                    Y2 = Y2 / RMS2  # Y2 Normalizada a su valor RMS

                elif len(X12[int(lv1 - tt -
                                 j):int(lv2 - tt -
                                        j)]) == lv:  # Condicion normal
                    Y2 = X12[int(lv1 - tt - j):int(lv2 - tt -
                                                   j)] * w1  # Ventana Y2
                    RMS2 = float(np.sqrt(np.mean(
                        Y2**2)))  # Valor cuadratico medio de Y2
                    Y2 = Y2 / RMS2  # Y2 Normalizada a su valor RMS

                else:
                    T = len(X12[int(lv1 - tt - j):int(lv2 - tt -
                                                      j)])  # Ultima ventana
                    TT = np.append(X12[int(lv1 - tt - j):int(lv2 - tt - j)],
                                   np.zeros(lv - T))  # Ventana Y2
                    Y2 = TT * w1
                    RMS2 = float(np.sqrt(np.mean(
                        Y2**2)))  # Valor cuadratico medio de Y2
                    Y2 = Y2 / float(RMS2)  # Y2 Normalizada a su valor RMS

                if RMS2 / rms2 > g:  # Gate de la senal desplazada
                    m = 1  # Reset del coeficiente de corrimiento maximo por amplitud
                    c[j + r] = signal.correlate(
                        Y1, Y2, 'valid', 'fft')  # Correlacion de senales
                    C = max(c) / float(lv)  # Valor de correlacion maxima

                    if C >= CCM:  # Condicion para valores de correlacion por debajo del umbral CCM
                        cm = np.argmax(
                            c) - r  # Posicion del valor de maxima correlacion
                        t1[i - u / lv] = cm
                        n = 1  # Reset del coeficiente de corrimiento maximo por correlacion
                        CC[i] = C  # Vector de valores maximos de correlacion

                    else:
                        cm = 0
                        CC[i] = CCM

                        if n < nm:
                            n += 1

                    N[i] = n  # Vector de coeficientes de correccion por umbral de correlacion

                else:
                    t1[i - u / lv] = 0

                    if m < mm:
                        m += 1

        else:
            t1[i - u / lv] = 0

            if m < mm:
                m += 1

        M[i] = m  # Vector de coeficientes de correccion por umbral de amplitud

        ####### Vectores de corrimientos tt y ta ########
        tt = sum(t1)
        ta[i] = tt

    return t0, t1, ta, l, CC, N, M
Esempio n. 5
0
    def merge(self, to_excel, from_excel_list, from_keys):
        #statistic
        contract_num = {}
        contract_amount = {}
        contract_detail = {}
        for idx, key in enumerate(from_keys):
            from_excel = from_excel_list[idx]
            contract_num[key] = {
                "this_month": {},
                "last_month": {},
                "smly": {}
            }
            contract_amount[key] = {
                "this_month": {},
                "last_month": {},
                "smly": {}
            }
            contract_detail[key] = {}
            smly_num = contract_num[key]["smly"]
            smly_num["sum"] = from_excel.get_value(2, "B7", -1, 0, int)
            smly_num["carry"] = from_excel.get_value(2, "C7", -1, 0, int)
            smly_num["new"] = from_excel.get_value(2, "E7", -1, 0, int)
            smly_num["accum"] = from_excel.get_value(2, "D7", -1, 0, int)

            thism_num = contract_num[key]["this_month"]
            thism_num["sum"] = from_excel.get_value(2, "F7", -1, 0, int)
            thism_num["carry"] = from_excel.get_value(2, "G7", -1, 0, int)
            thism_num["accum"] = from_excel.get_value(2, "H7", -1, 0, int)
            thism_num["new"] = from_excel.get_value(2, "I7", -1, 0, int)

            smly_amount = contract_amount[key]["smly"]
            smly_amount["sum"] = from_excel.get_value(2, "J7", -1, 0.0, float)
            smly_amount["carry"] = from_excel.get_value(
                2, "K7", -1, 0.0, float)
            smly_amount["accum"] = from_excel.get_value(
                2, "L7", -1, 0.0, float)
            smly_amount["new"] = from_excel.get_value(2, "M7", -1, 0.0, float)

            thism_amount = contract_amount[key]["this_month"]
            thism_amount["sum"] = from_excel.get_value(2, "N7", -1, 0.0, float)
            thism_amount["carry"] = from_excel.get_value(
                2, "O7", -1, 0.0, float)
            thism_amount["accum"] = from_excel.get_value(
                2, "P7", -1, 0.0, float)
            thism_amount["new"] = from_excel.get_value(2, "Q7", -1, 0.0, float)

            #details
            details = contract_detail[key]
            for d_idx in range(8):
                lin_name = d_idx + 8
                busi_name = from_excel.get_value(2, "A%d" % (lin_name), -1)
                details[busi_name] = {
                    "num": {
                        "this_month": {},
                        "last_month": {},
                        "smly": {}
                    },
                    "amount": {
                        "this_month": {},
                        "last_month": {},
                        "smly": {}
                    }
                }
                num = details[busi_name]["num"]
                num["smly"]["sum"] = from_excel.get_value(
                    2, "B%d" % lin_name, -1, 0.0, float)
                num["smly"]["carry"] = from_excel.get_value(
                    2, "C%d" % lin_name, -1, 0.0, float)
                num["smly"]["accum"] = from_excel.get_value(
                    2, "D%d" % lin_name, -1, 0.0, float)
                num["smly"]["new"] = from_excel.get_value(
                    2, "E%d" % lin_name, -1, 0.0, float)

                num["this_month"]["sum"] = from_excel.get_value(
                    2, "F%d" % lin_name, -1, 0.0, float)
                num["this_month"]["carry"] = from_excel.get_value(
                    2, "G%d" % lin_name, -1, 0.0, float)
                num["this_month"]["accum"] = from_excel.get_value(
                    2, "H%d" % lin_name, -1, 0.0, float)
                num["this_month"]["new"] = from_excel.get_value(
                    2, "I%d" % lin_name, -1, 0.0, float)

                amount = details[busi_name]["amount"]
                amount["smly"]["sum"] = from_excel.get_value(
                    2, "J%d" % lin_name, -1, 0.0, float)
                amount["smly"]["carry"] = from_excel.get_value(
                    2, "K%d" % lin_name, -1, 0.0, float)
                amount["smly"]["accum"] = from_excel.get_value(
                    2, "L%d" % lin_name, -1, 0.0, float)
                amount["smly"]["new"] = from_excel.get_value(
                    2, "M%d" % lin_name, -1, 0, float)

                amount["this_month"]["sum"] = from_excel.get_value(
                    2, "N%d" % lin_name, -1, 0.0, float)
                amount["this_month"]["carry"] = from_excel.get_value(
                    2, "O%d" % lin_name, -1, 0.0, float)
                amount["this_month"]["accum"] = from_excel.get_value(
                    2, "P%d" % lin_name, -1, 0.0, float)
                amount["this_month"]["new"] = from_excel.get_value(
                    2, "Q%d" % lin_name, -1, 0.0, float)
        out_ws = to_excel.get_new_sheet(self.title)
        out_ws['A1'].font = pxl.styles.Font(name=u'宋体', size=16, bold=True)
        out_ws['A1'] = self.title + u'(单位:万元)'
        out_ws.merge_cells('A1:K1')
        titles = [
            u'单位名称', u'本月新签合同额', u'本月累计新签合同额', u'本月合同总额', u'去年同期新签合同额',
            u'去年同期累计新签合同额', u'去年同期合同总额', u'本月累计合同份数', u'本月新签合同份数', u'本月合同总份数',
            u'去年同期累计合同份数', u'去年同期新签合同份数', u'去年同期合同总份数'
        ]

        cell_name = 'A2'
        for i, t in enumerate(titles):
            out_ws[cell_name] = t
            out_ws.merge_cells(
                '%s:%s' % (cell_name, get_next_cell_name(cell_name, True)))
            cell_name = get_next_cell_name(cell_name)

        start_cell_name = 'A4'
        format_start = 'A1'
        new_sum_amount = 0
        for key in from_keys:
            new_sum_amount += contract_amount[key]['this_month']['new']
        for key in from_keys:
            out_ws[start_cell_name] = key
            cur_cell = get_next_cell_name(start_cell_name)
            out_ws[cur_cell] = contract_amount[key]['this_month']['new']
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = contract_amount[key]['this_month']['accum']
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = contract_amount[key]['this_month']['sum']
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = contract_amount[key]['smly']['new']
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = contract_amount[key]['smly']['accum']
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = contract_amount[key]['smly']['sum']

            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = contract_num[key]['this_month']['accum']
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = contract_num[key]['this_month']['new']
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = contract_num[key]['this_month']['sum']
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = contract_num[key]['smly']['accum']
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = contract_num[key]['smly']['new']
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = contract_num[key]['smly']['sum']

            format_end = cur_cell
            start_cell_name = get_next_cell_name(start_cell_name, True)

        bd = pxl.styles.Side(style='thin', color='000000')
        to_excel.style_range(cell_range="%s:%s" % (format_start, format_end), \
                border=pxl.styles.Border(left=bd, top=bd, right=bd, bottom=bd), \
                fill=None, \
                alignment=pxl.styles.Alignment(horizontal='center', vertical='center'))

        start_cell_name = get_next_cell_name(start_cell_name, True)
        start_cell_name = get_next_cell_name(start_cell_name, True)
        out_ws[start_cell_name] = u'本月各公司各类项目合同额'
        out_ws[start_cell_name].font = pxl.styles.Font(name=u'宋体',
                                                       size=16,
                                                       bold=True)
        format_start = start_cell_name
        busi_names = [
            u'测绘地理信息', u'管线工程', u'应用地球物理工程', u'新兴业务航空遥感', u'新兴业务智慧城市',
            u'其他新兴业务\n(测绘地理信息类)', u'其他新兴业务\n(管线工程类)', u'其他新兴业务\n(应用地球物理工程类)'
        ]
        titles = copy.deepcopy(busi_names)
        titles.insert(0, u'各单位名称')
        titles.extend([u'新兴业务新签合同', u'备注'])
        out_ws.merge_cells(
            '%s:%s' % (start_cell_name,
                       get_next_cell_name(start_cell_name, False,
                                          len(titles) + len(busi_names) - 1)))
        start_cell_name = get_next_cell_name(start_cell_name, True)
        cell_name = start_cell_name
        format_end = start_cell_name
        for i, t in enumerate(titles):
            out_ws[cell_name] = t
            cell_end = cell_name
            if t in busi_names:
                cell_end = get_next_cell_name(get_next_cell_name(cell_name))
            else:
                cell_end = get_next_cell_name(cell_name, True)
            out_ws.merge_cells('%s:%s' % (cell_name, cell_end))
            if t in busi_names:
                first_cell = get_next_cell_name(cell_name, True)
                second_cell = get_next_cell_name(
                    get_next_cell_name(cell_name, True))
                third_cell = get_next_cell_name(
                    get_next_cell_name(get_next_cell_name(cell_name, True)))
                out_ws[first_cell] = u'新增合同额'
                out_ws[second_cell] = u'今年累计合同额'
                out_ws[third_cell] = u'去年累计合同额'
                format_end = second_cell
                cell_name = get_next_cell_name(
                    get_next_cell_name(get_next_cell_name(cell_name)))
            else:
                format_end = get_next_cell_name(cell_name, True)
                cell_name = get_next_cell_name(cell_name)

        bd = pxl.styles.Side(style='thin', color='000000')
        to_excel.style_range("%s:%s" % (start_cell_name, format_end), \
                border=pxl.styles.Border(left=bd, top=bd, right=bd, bottom=bd), \
                fill=pxl.styles.PatternFill('solid', fgColor='ffff00'), \
                font=pxl.styles.Font(name=u'宋体', size=14, bold=True))

        start_cell_name = get_next_cell_name(start_cell_name, True)
        start_cell_name = get_next_cell_name(start_cell_name, True)

        new_busi_info = {}
        for key in from_keys:
            out_ws[start_cell_name] = key
            cur_cell = get_next_cell_name(start_cell_name)
            new_busi_sum = 0.0
            for busi in busi_names:
                out_ws[cur_cell] = contract_detail[key][busi]['amount'][
                    'this_month']['new']
                cur_cell = get_next_cell_name(cur_cell)
                out_ws[cur_cell] = contract_detail[key][busi]['amount'][
                    'this_month']['accum']
                cur_cell = get_next_cell_name(cur_cell)
                out_ws[cur_cell] = contract_detail[key][busi]['amount'][
                    'smly']['accum']
                cur_cell = get_next_cell_name(cur_cell)
                if busi.find(u'新兴') >= 0:
                    new_busi_sum += contract_detail[key][busi]['amount'][
                        'this_month']['new']
                    if contract_detail[key][busi]['amount']['this_month'][
                            'new'] > 0.0:
                        if key not in new_busi_info:
                            new_busi_info[key] = []
                        new_busi_info[key].append(busi)
            out_ws[cur_cell] = new_busi_sum
            cur_cell = get_next_cell_name(cur_cell)
            if key in new_busi_info:
                out_ws[cur_cell] = u"、".join(new_busi_info[key])
            format_end = cur_cell
            start_cell_name = get_next_cell_name(start_cell_name, True)
        to_excel.style_range(cell_range="%s:%s" % (format_start, format_end),
                             alignment=pxl.styles.Alignment(
                                 horizontal='center', vertical='center'))
        #every business
        busi_new_amount = [0.0] * len(busi_names)
        busi_accum_amount = [0.0] * len(busi_names)
        all_busi_accum_amount = 0.0
        for i, busi in enumerate(busi_names):
            for key in from_keys:
                busi_new_amount[i] += contract_detail[key][busi]['amount'][
                    'this_month']['new']
                busi_accum_amount[i] += contract_detail[key][busi]['amount'][
                    'this_month']['accum']
                all_busi_accum_amount += contract_detail[key][busi]['amount'][
                    'this_month']['accum']

        start_cell_name = get_next_cell_name(start_cell_name, True)
        single_tname = [u'新增合同额', u'今年累计合同额', u'去年累计合同额']
        single_key = [
            'amount:this_month:new', 'amount:this_month:accum',
            'amount:smly:accum'
        ]
        for idx, tname in enumerate(single_tname):
            format_start = start_cell_name
            out_ws[start_cell_name] = u'按版块各数据单表:%s' % tname
            titles = [
                u'各单位名称',
            ]
            titles.extend(busi_names)
            out_ws.merge_cells('%s:%s' %
                               (start_cell_name,
                                get_next_cell_name(start_cell_name, False,
                                                   len(titles) - 1)))
            start_cell_name = get_next_cell_name(start_cell_name, True)
            cell_name = start_cell_name
            for t in titles:
                out_ws[cell_name] = t
                cell_name = get_next_cell_name(cell_name)
            start_cell_name = get_next_cell_name(start_cell_name, True)
            for key in from_keys:
                out_ws[start_cell_name] = key
                cur_cell = get_next_cell_name(start_cell_name)
                for busi in busi_names:
                    out_ws[cur_cell] = get_keys(contract_detail[key][busi],
                                                single_key[idx])
                    format_end = cur_cell
                    cur_cell = get_next_cell_name(cur_cell)
                start_cell_name = get_next_cell_name(start_cell_name, True)

            to_excel.style_range(cell_range='%s:%s' % (format_start, format_end), \
                    border=pxl.styles.Border(left=bd, top=bd, right=bd, bottom=bd), \
                    fill=None, \
                    font=pxl.styles.Font(name=u'宋体', size=12), \
                    alignment=pxl.styles.Alignment(horizontal='center', vertical='center'))

        start_cell_name = get_next_cell_name(start_cell_name, True)
        format_start = start_cell_name
        out_ws[start_cell_name] = u'各类项目本月合同额统计'
        out_ws[start_cell_name].font = pxl.styles.Font(name=u'宋体',
                                                       size=16,
                                                       bold=True)
        out_ws[start_cell_name].alignment = pxl.styles.Alignment(
            horizontal='center')
        titles = [u'各单位名称', u'新签合同额', u'新签合同额占比', u'累计合同额', u'累计合同额占比']
        out_ws.merge_cells('%s:%s' %
                           (start_cell_name,
                            get_next_cell_name(start_cell_name, False,
                                               len(titles) - 1)))

        start_cell_name = get_next_cell_name(start_cell_name, True)
        cur_cell = start_cell_name
        title_start = start_cell_name
        for t in titles:
            out_ws[cur_cell] = t
            cur_cell = get_next_cell_name(cur_cell)
        start_cell_name = get_next_cell_name(start_cell_name, True)

        to_excel.style_range("%s:%s" % (title_start, get_next_cell_name(title_start, False, len(titles) - 1)), \
                border=pxl.styles.Border(left=bd, top=bd, right=bd, bottom=bd), \
                fill=pxl.styles.PatternFill('solid', fgColor='ffff00'), \
                font=pxl.styles.Font(name=u'宋体', size=14, bold=True))

        for i, busi in enumerate(busi_names):
            cur_cell = start_cell_name
            out_ws[cur_cell] = busi
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = busi_new_amount[i]
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = division(busi_new_amount[i], new_sum_amount)
            out_ws[cur_cell].number_format = '0.00%'
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = busi_accum_amount[i]
            cur_cell = get_next_cell_name(cur_cell)
            out_ws[cur_cell] = division(busi_accum_amount[i],
                                        all_busi_accum_amount)
            out_ws[cur_cell].number_format = '0.00%'
            format_end = cur_cell
            start_cell_name = get_next_cell_name(start_cell_name, True)

        to_excel.style_range(cell_range="%s:%s" % (format_start, format_end),
                             alignment=pxl.styles.Alignment(
                                 horizontal='center', vertical='center'))

        to_excel.fit_width(2)
Esempio n. 6
0
def get_DNN_info_general(sess, first_jpeg_image, n_images=50):
    #def get_DNN_info_general(sess, first_jpeg_image, n_images = 3):

    graph_def = sess.graph.as_graph_def(add_shapes=True)

    all_tensors = [
        tensor for op in tf.get_default_graph().get_operations()
        for tensor in op.values()
    ]
    all_layers = []
    input_tensor_list = []
    conv_tensor_list = []
    padding_tensor_list = []
    sw_tensor_list = []
    sh_tensor_list = []
    first_input_tensor = []
    k_tensor_list = []
    kw_tensor_list = []
    kh_tensor_list = []

    # loop on all nodes in the graph
    for nid, n in enumerate(graph_def.node):
        try:

            if nid == 0:
                first_input_tensor.append(n.name + ':0')

            #print(n.name)
            if (
                    'Conv2D' in n.name or 'convolution' in n.name
            ) and '_bn_' not in n.name and 'Logits' not in n.name and 'logits' not in n.name:

                output_tensor_name = n.name + ':0'
                input_tensor_name = n.input[0] + ':0'
                input_tensor = sess.graph.get_tensor_by_name(input_tensor_name)
                input_tensor_list.append(input_tensor_name)
                conv_tensor_list.append(
                    sess.graph.get_tensor_by_name(output_tensor_name))

                if 'padding' in n.attr.keys():
                    padding_type = n.attr['padding'].s.decode(encoding='utf-8')
                    padding_tensor_list.append(padding_type)
                if 'strides' in n.attr.keys():
                    art_tensor_name = n.name + ':0'
                    strides_list = [int(a) for a in n.attr['strides'].list.i]
                    Sh = strides_list[1]
                    Sw = strides_list[2]
                    sh_tensor_list.append(Sh)
                    sw_tensor_list.append(Sw)

                conv_tensor_params_name = n.input[1] + ':0'
                conv_tensor_params = sess.graph.get_tensor_by_name(
                    conv_tensor_params_name)
                filter_shape = conv_tensor_params.shape
                Kh = filter_shape[0]
                Kw = filter_shape[1]
                K = filter_shape[3]
                k_tensor_list.append(K)
                kh_tensor_list.append(Kh)
                kw_tensor_list.append(Kw)

        except ValueError:
            print('%s is an Op.' % n.name)

    # ensure that created lists have the same length
    assert (len(sw_tensor_list) == len(sh_tensor_list) ==
            len(padding_tensor_list) == len(conv_tensor_list) ==
            len(input_tensor_list))
    assert (len(k_tensor_list) == len(kh_tensor_list) == len(kw_tensor_list) ==
            len(sw_tensor_list))

    # Write the header in text file
    txt_file = FLAGS.gen_dir + FLAGS.model_name + '.info'
    info_file = open(txt_file, 'w')
    current_string = (
        '====input_tensor_name\toutput_tensor_name\tIh\tIw\tOh\tOw\tKh\tKw\tSh\tSw\tIc\tK\tru\tlowering_density====\n'
    )
    info_file.write(current_string)

    print('Fetched Primary information about DNN...')

    # Loop through convolutions to get the conv dimensions
    file_list = FLAGS.gen_dir + "file_list"
    conv_shape = FLAGS.gen_dir + "conv_shape"
    file_list_file = open(file_list, 'w')
    conv_shape_file = open(conv_shape, 'w')

    for ic, c in enumerate(conv_tensor_list):

        # Get image data
        image_data = get_image_data(first_jpeg_image)

        # Run the first image
        current_feature_map, input_to_feature_map = run_DNN_for_analysis(
            sess, ic, c, input_tensor_list, first_input_tensor, image_data)

        _, Oh, Ow, _ = current_feature_map.shape
        In, Ih, Iw, Ic = input_to_feature_map.shape
        K, Kh, Kw, = k_tensor_list[ic], kh_tensor_list[ic], kw_tensor_list[ic]
        Sh, Sw = sh_tensor_list[ic], sw_tensor_list[ic]
        padding_type = padding_tensor_list[ic]

        input_tensor_name = input_tensor_list[ic]
        output_tensor_name = c.name

        # Create the conv_layer
        conv_layer = Conv_Layer(input_tensor_name,
                                output_tensor_name,
                                K,
                                Kh,
                                Kw,
                                Sh,
                                Sw,
                                Oh,
                                Ow,
                                Ih,
                                Iw,
                                Ic,
                                In,
                                padding=padding_type)
        conv_layer.padding_cal()
        # print(input_tensor_name, output_tensor_name)
        # Calculate the densities
        input_to_feature_map = np.squeeze(input_to_feature_map)

        ####################################### CUDA data ########################################################

        # Data for preformance paper
        # File name the have the conv layer intput
        input_tensor_FeatureMap_fileName = (FLAGS.model_name +
                                            "_Conv_%d_ImgID_%d") % (ic, 1)

        file_list_file.write(input_tensor_FeatureMap_fileName + "\n")
        current_string = ("%d") % (Ih)
        conv_shape_file.write(current_string + "\n")

        conv_fileName = FLAGS.conv + input_tensor_FeatureMap_fileName
        conv_file = open(conv_fileName, 'w')
        for i_h in range(0, Ih):
            for i_w in range(0, Iw):
                conv_file.write(str(input_to_feature_map[i_h, i_w, 0]) + '\t')
        conv_file.close()

        ####################################### END CUDA data ####################################################

        # lowering_matrix                 = conv_layer.preprocessing_layer(np.squeeze(input_to_feature_map))
        lowering_matrix = conv_layer.preprocessing_layer(input_to_feature_map)

        #print('********* PADDING TYPE ', conv_layer.padding, ' PADDINGS: ' , conv_layer.paddings, ' Input: ', input_tensor_name, ' out: ', output_tensor_name,
        #        ' Ih: ', conv_layer.Ih)

        # Get all layers
        all_layers.append(conv_layer)

        print('[%s] Analyzed Conv Node %d' % (FLAGS.model_name, ic))

    print('Reset the session')
    config = tf.ConfigProto(device_count={'GPU': 0})
    sess = tf.Session(config=config)
    create_graph()
    # Loop through images to get the average density for images:
    for imgID in range(2, FLAGS.END + 1):
        current_jpeg_image = org_image_dir + '/shard-' + str(0) + '/' + str(
            1) + '/' + 'ILSVRC2012_val_' + str(imgID).zfill(8) + '.JPEG'
        image_data = get_image_data(current_jpeg_image)

        print('[%s] %s' % (FLAGS.model_name, current_jpeg_image))

        # Loop through all convs in the model to update their densities:

        for ic, c in enumerate(conv_tensor_list):

            # Run the DNN
            current_feature_map, input_to_feature_map = run_DNN_for_analysis(
                sess, ic, c, input_tensor_list, first_input_tensor, image_data)

            # Get the old_conv_layer in a new deep copy
            old_conv_layer = copy.deepcopy(all_layers[ic])

            # Calculate the densities of old_conv_layer
            input_to_feature_map = np.squeeze(input_to_feature_map)
            ####################################### CUDA data ########################################################

            # Data for preformance paper
            # File name the have the conv layer intput
            input_tensor_FeatureMap_fileName = (
                FLAGS.model_name + "_Conv_%d_ImgID_%d") % (ic, imgID)
            file_list_file.write(input_tensor_FeatureMap_fileName + "\n")
            current_string = ("%d") % (Ih)
            conv_shape_file.write(current_string + "\n")

            conv_fileName = FLAGS.conv + input_tensor_FeatureMap_fileName
            conv_file = open(conv_fileName, 'w')
            for i_h in range(0, Ih):
                for i_w in range(0, Iw):
                    conv_file.write(
                        str(input_to_feature_map[i_h, i_w, 0]) + '\t')
            conv_file.close()

            ####################################### END CUDA data ####################################################
            lowering_matrix = old_conv_layer.preprocessing_layer(
                input_to_feature_map)
            # lowering_matrix                 = old_conv_layer.preprocessing_layer(np.squeeze(input_to_feature_map))
            # Update the densities to sum
            all_layers[ic].ru += old_conv_layer.ru
            all_layers[ic].lowering_density += old_conv_layer.lowering_density

            if not ic % 10:
                print('[%s] Analyzed Conv Node %d' % (FLAGS.model_name, ic))

            if ic == int(0.25 * len(conv_tensor_list)) or ic == int(
                    0.5 * len(conv_tensor_list)) or ic == int(
                        0.75 * len(conv_tensor_list)):
                # reset the session:
                config = tf.ConfigProto(device_count={'GPU': 0})
                sess = tf.Session(config=config)
                create_graph()

            #print('i-', ic, ' ', input_tensor_list[ic],
            #        ' ru: ' , old_conv_layer.ru, ' ru2: ', old_conv_layer.lowering_density, ' sum1: ', all_layers[ic].ru, ' sum2: ', all_layers[ic].lowering_density)

        # Reset the session
        config = tf.ConfigProto(device_count={'GPU': 0})
        sess = tf.Session(config=config)
        create_graph()
    file_list_file.close()
    conv_shape_file.close()

    # Get the average density and save it in *.info file:
    txt_file = FLAGS.gen_dir + FLAGS.model_name + '.info'
    info_file = open(txt_file, 'a')
    for ilayer, layer in enumerate(all_layers):
        all_layers[ilayer].ru = all_layers[ilayer].ru / n_images
        all_layers[ilayer].lowering_density = all_layers[
            ilayer].lowering_density / n_images

        #        current_string = ('%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%f\t%f\n' %
        #                (layer.input_tensor_name, layer.output_tensor_name, layer.Ih, layer.Iw, layer.Oh, layer.Ow,
        #                    layer.Kh, layer.Kw,
        #                    layer.Sh, layer.Sw,
        #                    layer.Ic, layer.K,
        #                    layer.ru, layer.lowering_density))

        current_string = (
            '%d & %d & %d & %d & %d & %d & %d & %d & %d & %d & %d & %.2f & %.2f \\\\\n'
            % (ilayer, layer.Ih, layer.Iw, layer.Oh, layer.Ow, layer.Kh,
               layer.Kw, layer.Sh, layer.Sw, layer.Ic, layer.K, layer.ru,
               layer.lowering_density))
        info_file.write(current_string)
        #print(current_string)

    #info_file.write('Extracted info for these %d layers... No Risk No Fun :) ' % len(all_layers))
    info_file.close()

    print('Extracted info for these %d layers... No Risk No Fun :) ' %
          len(all_layers))
    print('This code should work without exit.... Done!')
    exit(0)
    return all_layers
Esempio n. 7
0
    def readfiles(self, filepath):  #存入数据
        self.progressBar.setVisible(True)
        self.statusBar().showMessage("正在进行数据转换...")
        self.progressBar.setValue(0)
        files = os.listdir(filepath)
        #排除隐藏文件和文件夹
        for f in files:
            if (os.path.isdir(filepath + '/' + f)):
                # 排除隐藏文件夹。因为隐藏文件夹过多
                if (f[0] == '.'):
                    pass
                else:
                    # 添加非隐藏文件夹
                    self.dirList.append(f)
            if (os.path.isfile(filepath + '/' + f)):
                # 添加文件
                if (os.path.splitext(f)[1] == ".txt"):
                    self.filenames.append(f)
        p = 1
        print(self.filenames)

        for f in self.filenames:
            self.statusBar().showMessage("正在转换 " + str(p) + "/" +
                                         str(len(self.filenames)))
            data = dataclass()
            data.filepath = filepath
            datarow = open(filepath + '/' + f)  #读取的整个原始文件数据
            datarowlines = datarow.readlines()  #读取的整个原始文件的数据,按行分割
            datapar = []  #真正的每行数据数组
            for line in datarowlines:
                linenew = line.strip()
                if (linenew != ""):
                    datapar.append(linenew)
            # self.ACQ_Time=re.search("(\d{4}-\d{1,2}-\d{1,2}\s*\d{1,2}:\d{1,2}:\d{1,2}:\s*\d{1,3})",datapar[1])
            temptime = re.search(
                "\d{4}-\s*\d{1,2}-\s*\d{1,2}\s*\d{1,2}:\s*\d{1,2}:\s*\d{1,2}:\s*\d{1,3}",
                datapar[1]).group(0)
            timelist = re.split('[- :]\s*', temptime)
            # print(timelist)
            timestr = timelist[0] + "-" + timelist[1] + "-" + timelist[
                2] + "  " + timelist[3] + ":" + timelist[4] + ":" + timelist[
                    5] + "." + timelist[6]
            data.ACQ_Time = datetime.strptime(timestr, '%Y-%m-%d  %H:%M:%S.%f')
            data.Project = datapar[2].strip(
                datapar[2].split(": ")[0]).strip(": ")
            data.Name = datapar[3].strip(datapar[3].split(": ")[0]).strip(": ")
            data.part = datapar[4].strip(datapar[4].split(": ")[0]).strip(": ")
            data.Operator = datapar[5].strip(
                datapar[5].split(": ")[0]).strip(": ")
            data.Desc = datapar[6].strip(datapar[6].split(": ")[0]).strip(": ")
            data.Excited_Peroid = int(datapar[9].strip(
                datapar[9].split(": ")[0]).strip(": "))
            data.Excited_Time = int(datapar[10].strip(
                datapar[10].split(": ")[0]).strip(": "))
            data.Acq_Delay_Time = int(datapar[11].strip(
                datapar[11].split(": ")[0]).strip(": "))
            data.Gate_Time = int(datapar[12].strip(
                datapar[12].split(": ")[0]).strip(": "))
            data.Count_Num_per_gate = int(datapar[13].strip(
                datapar[13].split(": ")[0]).strip(": "))
            data.Repeat_Times = int(datapar[14].strip(
                datapar[14].split(": ")[0]).strip(": "))
            data.Acq_Gate_Times = int(datapar[15].strip(
                datapar[15].split(": ")[0]).strip(": "))
            data.Interval_per_Gate = int(datapar[16].strip(
                datapar[16].split(": ")[0]).strip(": "))
            data.Channel_Number = int(datapar[17].strip(
                datapar[17].split(": ")[0]).strip(": "))
            # print(data.ACQ_Time)
            #计算时间,以分钟为单位
            # minutecount=0
            # timelist=re.split('[- :]\s*',data.ACQ_Time)
            # data1 =timelist[0] + "-" + timelist[1] + "-" + timelist[2] + " " + timelist[3] + ":" + timelist[4] + ":" + timelist[5]
            #
            # year=(float(timelist[0])-2019)*364*24*60
            # mouth=(float(timelist[1])-1)*30.5*24*60
            # day=  (float(timelist[2])-1)*24*
            # print(data)

            datanum = int(data.Repeat_Times * data.Count_Num_per_gate)
            data.Pro_Data1 = np.zeros(data.Acq_Gate_Times *
                                      data.Count_Num_per_gate).tolist()
            # [0 for i in range(data.Acq_Gate_Times*data.Count_Num_per_gate)]
            # print(data.Gate_Time)
            # print("len(data.Raw_Data1)",len(data.Pro_Data1))
            # print("data.Count_Num_per_gate*data.Gate_Time",data.Count_Num_per_gate*data.Gate_Time)

            for i in range(19, 19 + datanum):
                data.Raw_Data1.append(int(datapar[i]))
            if (data.Channel_Number == "2"):
                for i in range(19 + datanum + 1, 19 + datanum + 1 + datanum):
                    data.Raw_Data2.append(int(datapar[i]))
            # print(len(data.Raw_Data1))
            # print(len(data.Raw_Data2))

            dScale = data.Count_Num_per_gate * 1000 / (data.Gate_Time *
                                                       data.Repeat_Times)
            for i in range(int(data.Acq_Gate_Times)):
                for j in range(int(data.Count_Num_per_gate)):
                    ncps = 0
                    for k in range(int(data.Repeat_Times)):
                        ncps += data.Raw_Data1[k * data.Count_Num_per_gate +
                                               j + i * datanum]
                    data.Pro_Data1[j * data.Acq_Gate_Times + i] = ncps * dScale
            data.Interval = float(data.Gate_Time) / len(data.Pro_Data1)
            for i in range(len(data.Pro_Data1)):
                data.Pro_Data1_X.append(i * data.Interval)
            # print(data.Pro_Data1)
            data.Max = np.max(data.Pro_Data1)
            data.Min = np.min(data.Pro_Data1)
            data.cutendnum1 = len(data.Pro_Data1) - 1
            #复制原始数据到Cut
            data.Cut_Data1 = copy.deepcopy(data.Pro_Data1)
            data.Cut_Data1_X = copy.deepcopy(data.Pro_Data1_X)
            if (len(data.Cut_Data1) > self.maxCol):
                self.maxCol = len(data.Cut_Data1)
            # print("data.Cut_Data1",data.Cut_Data1)
            self.filelist[f] = data

            # print(self.filelist[f].Pro_Data1)
            self.progressBar.setValue(p / len(self.filenames) * 100)

            p += 1
            self.statusBar().showMessage("完成!")
        self.progressBar.setVisible(False)
        self.statusBar().showMessage("数据转换成功!")