计量检验抽样方案程序

昨晚帮同学写的,不确定的就是第四栏的

2021/12/1

image.png

根据上图写的程序,第四栏可能不太对,

  1#!/usr/bin/env python
  2# -*- coding: utf-8 -*-
  3# @Time    : 2021/11/30 19:01
  4# @Author  : Aen
  5# @File    : get_virtual_pic.py
  6# @Software: PyCharm
  7import math
  8
  9import openpyxl
 10
 11
 12# data_list = []
 13# q_average = 0
 14
 15def reading_file():
 16    # xl = xlrd.open_workbook(r'reading_data.xlsx')
 17    # table = xl.sheets()[0]
 18    # print(table)
 19    # 加载workbook
 20    wb = openpyxl.load_workbook(r'./reading_data.xlsx')
 21    # print(wb)
 22    sheet = wb.worksheets[0]
 23    # print(sheet.max_row)
 24    # print(sheet.cell(1, 1).value)
 25    data_list = []
 26    q_average = 0
 27    for row in range(1, sheet.max_row + 1):
 28        data_list.append(sheet.cell(row, 1).value)
 29        q_average = q_average + sheet.cell(row, 1).value
 30    q_average = q_average / sheet.max_row
 31    # print(data_list)
 32    # print(q_average)
 33    return data_list, q_average, sheet.cell(1, 2).value, sheet.max_row, sheet.cell(2, 2).value
 34
 35
 36def get_s_number(data_all, average, all_number):
 37    sum = 0
 38    for n in data_all:
 39        sum = sum + math.pow(average - n, 2)
 40    # print(sum)
 41    return math.sqrt(sum / (all_number - 1))
 42
 43
 44def get_k_number(n, sample_size):
 45    tmp = 1.028
 46    if n > 3200:
 47        tmp = 0.234
 48    elif n >= 501:
 49        tmp = 0.295
 50    elif n >= 100:
 51        tmp = 0.379
 52    elif n >= 51:
 53        tmp = 0.848
 54    else:
 55        tmp = 1.028
 56    # return tmp
 57    return tmp / math.sqrt(sample_size)
 58
 59
 60def get_float(n):
 61    tmp = 0
 62    if n > 3200:
 63        tmp = 7
 64    elif n >= 501:
 65        tmp = 5
 66    elif n >= 100:
 67        tmp = 3
 68    elif n >= 51:
 69        tmp = 1
 70    else:
 71        tmp = 0
 72    return tmp
 73
 74
 75if __name__ == '__main__':
 76    print("============================说明============================")
 77    print("\n\n============因为有上下浮动,有四种情况输出============")
 78    print("\n===1.质量优秀 A")
 79    print("===2.质量还不错 B")
 80    print("===3.质量合格(合格比较差劲的一批货) C")
 81    print("===4.质量不合格,抽查不合格  D")
 82    print("\n-------->如果抽取的样本为10,只有优秀与不合格!")
 83    data_list, q_average, criterion_number, max_number, check_nums = reading_file()
 84    s = get_s_number(data_list, q_average, max_number)
 85    k = get_k_number(check_nums, max_number)
 86    up_down = get_float(check_nums)
 87
 88    right_num_high = criterion_number + up_down - (s * k)
 89    right_num_mid = criterion_number - (s * k)
 90    right_num_low = criterion_number - up_down - (s * k)
 91    left_num = q_average
 92    # print("==========")
 93    # print(left_num)
 94    # print(right_num_low)
 95    # print(right_num_mid)
 96    # print(right_num_high)
 97    # print("==========")
 98    print("\n----->结果<------:\n")
 99    print("     平均值q:        " + str(q_average))
100    print("     标注净含量Q:    " + str(criterion_number))
101    print("     修正因子λ :    " + str(k))
102    print("     标准偏差值s:    " + str(s))
103    print("     允许的短缺件数: " + str(up_down))
104    print("     Q - λs:       " + str(right_num_mid)+"\n")
105    if (left_num - right_num_high) >= 0:
106        print("     1.质量优秀 A")
107        print("     1.质量优秀 A")
108    elif (left_num - right_num_mid) >= 0:
109        print("     2.质量还不错 B")
110        print("     2.质量还不错 B")
111    elif (left_num - right_num_low) >= 0:
112        print("     3.质量合格(合格比较差劲的一批货) C")
113        print("     3.质量合格(合格比较差劲的一批货) C")
114    else:
115        print("     4.质量不合格,抽查不合格  D")
116        print("     4.质量不合格,抽查不合格  D")
117
118    input("\n输入任意字符退出.....")
119    # print(data_list)
120    # print(q_average)
121    # print(criterion_number)
122    # print(max_number)
123    # print(s)
124    # print(check_nums)
125    # print(k)
126    # print(s*k)
127    # print(up_down)


    


公众号'艾恩凝'
个人公众号
个人微信
个人微信
    吾心信其可行,
          则移山填海之难,
                  终有成功之日!
                                  ——孙文
    评论
    0 评论
avatar

取消