class Coffee_Class(): def __init__(self): self.aaa("c:\\data\\coffee_kiosk.png") print('커피 키오스크 시스템을 시작합니다.') #1. 주문 데이터를 쌓기 위한 딕셔너리 구성 코드, init 함수에 들어가니까 self. 붙여주기 self.cafe_dict = {} self.cafe_dict ['주문번호'] = [] self.cafe_dict ['주문시간'] = [] self.cafe_dict ['커피종류'] = [] self.cafe_dict ['수량'] = [] self.cafe_dict ['가격'] = []
#2. IF문을 여러번 나열하지 않기 위해 튜플/리스트를 활용하여 데이터 입력, init 함수에 들어가니까 self. 붙여주기 self.coffee_t = ['아메리카노', '카페라떼', '카페모카', '녹차라떼'] self.coffee_s = [20, 10, 30, 20] self.coffee_p = (1500, 2500, 3500, 3500)
#3. 주문번호와 쿠폰 변수를 만들어줌, init 함수에 들어가니까 self. 붙여주기 self.order_no = 0 # 주문번호 self.coupon = 0 #쿠폰수량 self.cup = 0
# 데이터 시각화 함수 def aaa(self, name): import PIL.Image as pilimg import numpy as np import matplotlib.pyplot as plt
im = pilimg.open(name) pix = np.array(im) plt.imshow(pix) ax = plt.gca() ax.axes.xaxis.set_visible(False) ax.axes.yaxis.set_visible(False)
plt.show() # 매출 계산하는 함수 def machul_sum(self): import pandas as pd from datetime import datetime now = str(datetime.now()) cafe = pd.DataFrame(self.cafe_dict) cafe.to_csv("c:\\data\\coffee_report_" + now[0:10] + '일_' + now[11:13] + '시_' + now[14:16] + '분_' + now[17:19] +'초' +".csv", encoding="ANSI") print('지금까지의 총 수익은', cafe['가격'].sum(), '원 입니다.' )
from matplotlib import font_manager, rc import matplotlib.pyplot as plt
font_name = font_manager.FontProperties(fname="c:/Windows/Fonts/malgun.ttf").get_name() rc('font', family=font_name)
result = cafe.groupby('커피종류')['가격'].sum().reset_index() result.columns=['커피종류', '각 매출액'] result.plot.pie(y='각 매출액', labels=result['커피종류'], autopct='%1.1f%%', colors=['skyblue', 'lightpink', 'lightgreen', 'peachpuff', 'lightcoral'] ) plt.legend(loc='best',bbox_to_anchor=(2, 1)) plt. title('커피종류별 매출액') plt.savefig("c:\\data\\coffee_report_" + now[0:10] + '일_' + now[11:13] + '시_' + now[14:16] + '분_' + now[17:19] +'초' + '.png', dpi = 300) #원형 그래프 자동 저장
return cafe # 판다스 테이블로 리턴하기 위해 꼭 써준다
#데이터 쌓는 함수 추가 def data_add(self, num): from datetime import datetime now = str( datetime.now() )
self.cafe_dict['주문번호'].append(self.order_no) self.cafe_dict['주문시간'].append(now) self.cafe_dict['커피종류'].append(self.coffee_t[num-1]) self.cafe_dict['수량'].append(self.cup) self.cafe_dict['가격'].append(self.total_price)
#커피 키오스크 출력 함수 def coffee_kiosk(self):
print('='*21,'MENU','='*21) self.aaa("c:\\data\\menu.png") print('='*48) #4. 주문 프로그램 시작 while True:
# 랜덤 음료추천 - shuffle 추가 from random import shuffle random_recommend = self.coffee_t shuffle(random_recommend) print('오늘의 추천 음료는 %s 입니다. ☺️' %random_recommend[0]) try: num = int(input('\n주문하시겠습니까? 메뉴를 골라주세요. 번호를 눌러주세요.')) except: return '잘못된 값을 입력하셨습니다. 숫자를 입력해주세요.' if self.coffee_s[0] == 0 and self.coffee_s[1] == 0 and self.coffee_s[2] == 0 and self.coffee_s[3] == 0: print('\n ** 모든 음료 재고가 소진되었습니다 직원에게 문의해주세요 **') break
if num < 5: if self.coffee_s[num-1] == 0: print('%s는 솔드아웃 되었습니다. 다시 선택해주세요' %self.coffee_t[num-1]) continue
print('%s를 선택하셨습니다.' %self.coffee_t[num-1])
self.cup = int(input('\n몇 잔 주문하시겠습니까?'))
if self.cup > self.coffee_s[num-1]: print('죄송합니다. 주문량에 비해 %s가 부족합니다.' %self.coffee_t[num-1]) print('현재 주문 가능한 수량은 %d입니다. 다시 입력해주세요.' %self.coffee_s[num-1],) continue
self.total_price = self.coffee_p[num-1]*self.cup print('\n결재하실 금액은 %d원 입니다.' %(self.total_price)) put_money = int(input('돈을 넣어주세요 ~'))
if put_money >= self.coffee_p[num-1]*self.cup: self.order_no = self.order_no + 1 print('\n주문번호 %d번님 %s %d잔 나왔습니다. 거스름돈은 %d원 입니다.' %(self.order_no, self.coffee_t[num-1], self.cup, put_money - self.coffee_p[num-1])) print('\n쿠폰이', self.cup, '개 발행되었습니다. 20개를 모으면 한 잔 무료입니다.') self.coupon += self.cup print('현재 가지고계신 쿠폰의 수는', self.coupon, '개 입니다.') print('무료 음료까지 남은 쿠폰의 갯수는', 20 - self.coupon, '개 입니다.') self.coffee_s[num-1] -= self.cup
else: print('%d원이 부족합니다. 잔돈이 반환됩니다' %(self.coffee_p[num-1]*self.cup - put_money)) continue # 위에서 만든 데이터 쌓는 함수를 여기에 추가해준다 self.data_add(num)
elif num == 100: #관리자 모드 실행 번호를 100번으로 변경했음 print('\n * 관리자 모드를 실행합니다 * \n') password = int(input('비밀번호를 입력하세요')) if password == 1234: print('\n [관리자 전용] 정산 내역을 출력합니다') break else: print('\n * 비밀번호가 틀렸습니다. 직원을 호출해주세요. * \n') continue
else: print('잘못된 번호입니다 처음화면으로 돌아갑니다') continue
return self.machul_sum() | |