Skip to content

Commit e06ac20

Browse files
committed
更新营养计算的算法,修正UI
1 parent cdc85b0 commit e06ac20

27 files changed

+421
-30
lines changed

AF.png

5.87 KB
Loading

AppIcon120.png

8.73 KB
Loading

AppIcon152.png

11.3 KB
Loading

AppIcon167.png

12.7 KB
Loading

AppIcon76.png

5.76 KB
Loading

AskFoodDemo.xcodeproj/project.pbxproj

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
E43187F01C5A1C1F00F40BFE /* Exten_UIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E43187EF1C5A1C1F00F40BFE /* Exten_UIView.swift */; };
3737
E43189AA1C5A7A6F00F40BFE /* Charts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E43189A51C5A7A4600F40BFE /* Charts.framework */; };
3838
E43189AB1C5A7A6F00F40BFE /* Charts.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E43189A51C5A7A4600F40BFE /* Charts.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
39+
E4C71ED01C5E2B5500A6FEB6 /* Protein.pdf in Resources */ = {isa = PBXBuildFile; fileRef = E4C71ECF1C5E2B5500A6FEB6 /* Protein.pdf */; };
40+
E4C71ED21C5E4A0F00A6FEB6 /* VC_c_s.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4C71ED11C5E4A0F00A6FEB6 /* VC_c_s.swift */; };
41+
E4EC222E1C5CDD3700E6D7C9 /* FoodPro.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4EC222D1C5CDD3600E6D7C9 /* FoodPro.swift */; };
3942
/* End PBXBuildFile section */
4043

4144
/* Begin PBXContainerItemProxy section */
@@ -123,6 +126,9 @@
123126
E43187ED1C5A15E200F40BFE /* You.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = You.png; sourceTree = "<group>"; };
124127
E43187EF1C5A1C1F00F40BFE /* Exten_UIView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Exten_UIView.swift; sourceTree = "<group>"; };
125128
E43188361C5A7A4600F40BFE /* Charts.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = Charts.xcodeproj; sourceTree = "<group>"; };
129+
E4C71ECF1C5E2B5500A6FEB6 /* Protein.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = Protein.pdf; sourceTree = "<group>"; };
130+
E4C71ED11C5E4A0F00A6FEB6 /* VC_c_s.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VC_c_s.swift; sourceTree = "<group>"; };
131+
E4EC222D1C5CDD3600E6D7C9 /* FoodPro.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoodPro.swift; sourceTree = "<group>"; };
126132
/* End PBXFileReference section */
127133

128134
/* Begin PBXFrameworksBuildPhase section */
@@ -172,6 +178,7 @@
172178
E43187A41C59F7CC00F40BFE /* ViewController.swift */,
173179
E43187C21C59F8F900F40BFE /* Color.swift */,
174180
E43187A61C59F7CC00F40BFE /* Main.storyboard */,
181+
E4C71ED11C5E4A0F00A6FEB6 /* VC_c_s.swift */,
175182
E43187D71C5A098500F40BFE /* VC_c.swift */,
176183
E43187D51C5A08CC00F40BFE /* VC_b.swift */,
177184
E43187D31C5A071F00F40BFE /* VC_a.swift */,
@@ -201,6 +208,7 @@
201208
E43187E91C5A156400F40BFE /* MessageBubble@2x.png */,
202209
E43187C51C59F9A700F40BFE /* button1.pdf */,
203210
E43187C61C59F9A700F40BFE /* button2.pdf */,
211+
E4C71ECF1C5E2B5500A6FEB6 /* Protein.pdf */,
204212
E43187C71C59F9A700F40BFE /* button3.pdf */,
205213
E43187C81C59F9A700F40BFE /* logo1.pdf */,
206214
E43187C91C59F9A700F40BFE /* logos.pdf */,
@@ -216,6 +224,7 @@
216224
E43187DA1C5A0CC200F40BFE /* NavigationDelegate.swift */,
217225
E43187DC1C5A0D8500F40BFE /* CiecleAnimation.swift */,
218226
E43188331C5A7A4600F40BFE /* Charts */,
227+
E4EC222D1C5CDD3600E6D7C9 /* FoodPro.swift */,
219228
);
220229
name = Model;
221230
sourceTree = "<group>";
@@ -368,6 +377,7 @@
368377
E43187EC1C5A15D500F40BFE /* Me.png in Resources */,
369378
E43187AA1C59F7CC00F40BFE /* Assets.xcassets in Resources */,
370379
E43187EA1C5A156400F40BFE /* MessageBubble@2x.png in Resources */,
380+
E4C71ED01C5E2B5500A6FEB6 /* Protein.pdf in Resources */,
371381
E43187CD1C59F9A700F40BFE /* logo1.pdf in Resources */,
372382
E43187CB1C59F9A700F40BFE /* button2.pdf in Resources */,
373383
E43187CC1C59F9A700F40BFE /* button3.pdf in Resources */,
@@ -400,9 +410,11 @@
400410
E43187A31C59F7CC00F40BFE /* AppDelegate.swift in Sources */,
401411
E43187D61C5A08CC00F40BFE /* VC_b.swift in Sources */,
402412
E43187F01C5A1C1F00F40BFE /* Exten_UIView.swift in Sources */,
413+
E4C71ED21C5E4A0F00A6FEB6 /* VC_c_s.swift in Sources */,
403414
E43187D21C59FD4200F40BFE /* VC2.swift in Sources */,
404415
E43187E21C5A151100F40BFE /* TableHeaderViewCell.swift in Sources */,
405416
E43187E81C5A154D00F40BFE /* MessageItem.swift in Sources */,
417+
E4EC222E1C5CDD3700E6D7C9 /* FoodPro.swift in Sources */,
406418
E43187D01C59FA5100F40BFE /* VC1.swift in Sources */,
407419
E43187DB1C5A0CC200F40BFE /* NavigationDelegate.swift in Sources */,
408420
E43187C31C59F8F900F40BFE /* Color.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "1"
4+
version = "2.0">
5+
<Breakpoints>
6+
<BreakpointProxy
7+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8+
<BreakpointContent
9+
shouldBeEnabled = "No"
10+
ignoreCount = "0"
11+
continueAfterRunningActions = "No"
12+
filePath = "AskFoodDemo/FoodPro.swift"
13+
timestampString = "475917094.579383"
14+
startingColumnNumber = "9223372036854775807"
15+
endingColumnNumber = "9223372036854775807"
16+
startingLineNumber = "46"
17+
endingLineNumber = "46"
18+
landmarkName = "computNutri(_:Sexof:Intensity:Time:)"
19+
landmarkType = "5">
20+
</BreakpointContent>
21+
</BreakpointProxy>
22+
</Breakpoints>
23+
</Bucket>
Binary file not shown.
Loading
Loading
Loading
Loading

AskFoodDemo/Assets.xcassets/AppIcon.appiconset/Contents.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
"scale" : "3x"
2222
},
2323
{
24-
"idiom" : "iphone",
2524
"size" : "60x60",
25+
"idiom" : "iphone",
26+
"filename" : "AppIcon120.png",
2627
"scale" : "2x"
2728
},
2829
{
@@ -51,18 +52,21 @@
5152
"scale" : "2x"
5253
},
5354
{
54-
"idiom" : "ipad",
5555
"size" : "76x76",
56+
"idiom" : "ipad",
57+
"filename" : "AppIcon76.png",
5658
"scale" : "1x"
5759
},
5860
{
59-
"idiom" : "ipad",
6061
"size" : "76x76",
62+
"idiom" : "ipad",
63+
"filename" : "AppIcon152.png",
6164
"scale" : "2x"
6265
},
6366
{
64-
"idiom" : "ipad",
6567
"size" : "83.5x83.5",
68+
"idiom" : "ipad",
69+
"filename" : "AppIcon167.png",
6670
"scale" : "2x"
6771
}
6872
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"filename" : "Protein.pdf",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Binary file not shown.

AskFoodDemo/Base.lproj/Main.storyboard

+27-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444
</connections>
4545
</navigationController>
4646
<placeholder placeholderIdentifier="IBFirstResponder" id="Srg-7m-Z6h" userLabel="First Responder" sceneMemberID="firstResponder"/>
47-
<customObject id="gfi-lu-SmH" customClass="NavigationControllerDelegate" customModule="AskFoodDemo" customModuleProvider="target"/>
47+
<customObject id="gfi-lu-SmH" customClass="NavigationControllerDelegate" customModule="AskFoodDemo" customModuleProvider="target">
48+
<connections>
49+
<outlet property="navigationController" destination="xfy-Uo-QSH" id="qeQ-Iw-SDi"/>
50+
</connections>
51+
</customObject>
4852
</objects>
4953
<point key="canvasLocation" x="948" y="316"/>
5054
</scene>
@@ -277,12 +281,32 @@
277281
</view>
278282
<connections>
279283
<outlet property="Button" destination="Pee-JW-09c" id="b0p-SK-8KI"/>
284+
<segue destination="vvo-E5-n7a" kind="show" identifier="toAbout" action="showDetailViewController:sender:" id="Gdn-LE-klI"/>
280285
</connections>
281286
</viewController>
282287
<placeholder placeholderIdentifier="IBFirstResponder" id="QtW-6W-CGc" userLabel="First Responder" sceneMemberID="firstResponder"/>
283288
</objects>
284289
<point key="canvasLocation" x="2307" y="1727"/>
285290
</scene>
291+
<!--c s-->
292+
<scene sceneID="2nM-rd-2sk">
293+
<objects>
294+
<viewController id="vvo-E5-n7a" customClass="VC_c_s" customModule="AskFoodDemo" customModuleProvider="target" sceneMemberID="viewController">
295+
<layoutGuides>
296+
<viewControllerLayoutGuide type="top" id="CsD-29-i1B"/>
297+
<viewControllerLayoutGuide type="bottom" id="2qa-GU-DqZ"/>
298+
</layoutGuides>
299+
<view key="view" contentMode="scaleToFill" id="uTq-3S-SXp">
300+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
301+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
302+
<color key="backgroundColor" red="0.94509803920000002" green="0.2901960784" blue="0.20784313730000001" alpha="1" colorSpace="calibratedRGB"/>
303+
<gestureRecognizers/>
304+
</view>
305+
</viewController>
306+
<placeholder placeholderIdentifier="IBFirstResponder" id="rqM-cr-zGd" userLabel="First Responder" sceneMemberID="firstResponder"/>
307+
</objects>
308+
<point key="canvasLocation" x="2967" y="1727"/>
309+
</scene>
286310
<!--a-->
287311
<scene sceneID="ofx-v5-SGy">
288312
<objects>
@@ -312,12 +336,12 @@
312336
<action selector="ClickBtn:" destination="LMN-Cg-nXG" eventType="touchUpInside" id="btU-0s-rcU"/>
313337
</connections>
314338
</button>
315-
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="c7U-4i-FXC">
339+
<textField hidden="YES" opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="c7U-4i-FXC">
316340
<rect key="frame" x="20" y="38" width="136" height="30"/>
317341
<fontDescription key="fontDescription" type="system" pointSize="14"/>
318342
<textInputTraits key="textInputTraits"/>
319343
</textField>
320-
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FyY-kP-1Fq">
344+
<button hidden="YES" opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FyY-kP-1Fq">
321345
<rect key="frame" x="203" y="38" width="46" height="30"/>
322346
<state key="normal" title="Button"/>
323347
<connections>

AskFoodDemo/CiecleAnimation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CircleTransitionAnimatorPopA: NSObject, UIViewControllerAnimatedTransition
6464
//containerView!.addSubview(toViewController.view)
6565
containerView!.insertSubview(toView, aboveSubview: fromView)
6666
// 4
67-
let circleMaskPathInitial = UIBezierPath(ovalInRect: button.frame)
67+
let circleMaskPathInitial = UIBezierPath(ovalInRect: VC_A_Frame!)
6868
let extremePoint = CGPointMake(button.center.x, button.center.y - CGRectGetHeight(toView.bounds)) // need more research
6969
let radius = sqrt(extremePoint.x * extremePoint.x + extremePoint.y * extremePoint.y)
7070
let circleMaskPathFinal = UIBezierPath(ovalInRect: CGRectInset(button.frame, -radius, -radius))

AskFoodDemo/FoodPro.swift

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
//
2+
// FoodPro.swift
3+
// AskFoodDemo
4+
//
5+
// Created by Colearo on 16/1/30.
6+
// Copyright © 2016年 Colearo. All rights reserved.
7+
//
8+
9+
import Foundation
10+
enum Sex{
11+
case Female
12+
case Male
13+
}
14+
enum LabourIntensity{
15+
case Small,Middle,High
16+
}
17+
enum TimeDur{
18+
case Morning,Noon,Night
19+
}
20+
enum ReturnStyle{
21+
case Input,Button
22+
}
23+
class nutrition {
24+
private let EER:[Sex: [LabourIntensity: [Int: Double]]] = [
25+
.Male: [
26+
.Small: [18: 2250,50: 2100,65: 2050,8: 1650,9: 1750,10: 1800,11: 2050,14: 2500],
27+
.Middle: [18: 2600,50: 2450,65: 2350,8: 1850,9: 2000,10: 2050,11: 2350,14:2850],
28+
.High: [18: 3000,50: 2800,8: 2100,9: 2250,10: 2300,11: 2600,14: 3200]
29+
],
30+
.Female: [.Small: [8: 1450,9: 1550,10: 1650,11: 1800,14: 2000,18: 1800,50: 1750,65: 1700],
31+
.Middle: [8: 1700,9: 1800,10: 1900,11: 2050,14: 2300,18: 2100,50: 2050,65: 1950],
32+
.High: [8: 1900,9: 2000,10: 2150,11: 2300,14: 2550,18: 2400,50: 2350]
33+
]
34+
]
35+
private let PRO:[Sex: [Int: Double]] = [.Female: [8: 40,9: 45,10: 50,11: 55,14: 60,18: 55],
36+
.Male: [8: 40,9: 45,10: 50,11: 60,14: 75,18: 65]]
37+
private let CHO:[Int: Double] = [1: 120,11: 150,18: 120]
38+
private let Ca:[Int: Double] = [7: 1000,11: 1200,14: 1000,18: 800,50: 1000]
39+
private let Vc:Double=100
40+
func computNutri(Age: Int,Sexof: Sex,Intensity: LabourIntensity,Time: TimeDur)->(Vc:Double,Ca:Double,CHO: Double,Fat: Double,EER: Double,PRO: Double)
41+
{
42+
var _EER=0.0,_PRO=0.0,_CHO=0.0,_Ca=0.0,_Vc=0.0,_Fat=0.0
43+
if Age>8 && Age<=11{
44+
_EER=self.EER[Sexof]![Intensity]![Age]!
45+
_Ca=((Age==11) ? self.Ca[Age] : self.Ca[7])!
46+
_CHO=self.CHO[1]!
47+
_PRO=self.PRO[Sexof]![Age]!
48+
}
49+
else if Age>11 && Age<14{
50+
_EER=self.EER[Sexof]![Intensity]![11]!
51+
_Ca=self.Ca[11]!
52+
_CHO=self.CHO[11]!
53+
_PRO=self.PRO[Sexof]![11]!
54+
}
55+
else if Age>=14 && Age<18{
56+
_EER=self.EER[Sexof]![Intensity]![14]!
57+
_Ca=self.Ca[14]!
58+
_CHO=self.CHO[11]!
59+
_PRO=self.PRO[Sexof]![14]!
60+
}
61+
else if Age>=18 && Age<50{
62+
_EER=self.EER[Sexof]![Intensity]![18]!
63+
_Ca=self.Ca[18]!
64+
_CHO=self.CHO[18]!
65+
_PRO=self.PRO[Sexof]![18]!
66+
}
67+
else if Age>=50 {
68+
_EER=self.EER[Sexof]![Intensity]![50]!
69+
_Ca=self.Ca[50]!
70+
_CHO=self.CHO[18]!
71+
_PRO=self.PRO[Sexof]![18]!
72+
}
73+
_Fat=_EER*0.25/9
74+
_Vc=self.Vc
75+
switch Time
76+
{
77+
case .Morning , .Night:
78+
_Vc*=0.3
79+
_EER*=0.3
80+
_Ca*=0.3
81+
_CHO*=0.3
82+
_Fat*=0.3
83+
_PRO*=0.3
84+
case .Noon:
85+
_Vc*=0.4
86+
_EER*=0.4
87+
_Ca*=0.4
88+
_CHO*=0.4
89+
_Fat*=0.4
90+
_PRO*=0.4
91+
}
92+
return (_Vc,_Ca,_CHO,_Fat,_EER,_PRO)
93+
}
94+
95+
}
96+
class askChat {
97+
private var openTime:NSDate
98+
private var chatStr:String?
99+
private var isAsked:[TimeDur: Bool]
100+
private var inputORbutton:ReturnStyle
101+
typealias TaggedToken = (String, String?)
102+
private let stopWord:[String]=["","","已经","别说","但是","","","况且","哪怕","","","","","","","","还是","当然","到底","",""]
103+
private let countWord:[String]=["","","","","","","","","","","","十几","","一些"]
104+
//private let
105+
func tagT(text: String, scheme: String) -> [String] {
106+
let options: NSLinguisticTaggerOptions = [.OmitWhitespace, .OmitPunctuation, .OmitOther]
107+
let tagger = NSLinguisticTagger(tagSchemes: NSLinguisticTagger.availableTagSchemesForLanguage("en"),
108+
options: Int(options.rawValue))
109+
tagger.string = text
110+
var tokens: [String] = []
111+
// Using NSLinguisticTagger
112+
tagger.enumerateTagsInRange(NSMakeRange(0, text.characters.count), scheme:scheme, options: options) { tag, tokenRange, _, _ in
113+
let token = (text as NSString).substringWithRange(tokenRange)
114+
for stop in self.stopWord{
115+
if token != stop{
116+
tokens.append(token)
117+
}
118+
}
119+
}
120+
return tokens
121+
}
122+
func partOfSpeech(text: String) -> [String] {
123+
return tagT(text,scheme: NSLinguisticTagSchemeNameTypeOrLexicalClass)
124+
}
125+
init(){
126+
self.openTime=NSDate()
127+
self.isAsked=[.Morning: false,.Noon: false,.Night: false]
128+
self.inputORbutton = .Button
129+
}
130+
func judgeTime()->TimeDur
131+
{
132+
let date=NSDateFormatter()
133+
self.openTime=NSDate()
134+
date.dateFormat="HH"
135+
let hour=Int(date.stringFromDate(openTime))
136+
if hour<=11{
137+
return .Morning
138+
}
139+
else if hour>=11&&hour<=16{
140+
return .Noon
141+
}
142+
else if hour>=17&&hour<=24{
143+
return .Night
144+
}
145+
return .Morning
146+
}
147+
/*func getReturned()->(strings:[String],returnsty:ReturnStyle)
148+
{
149+
150+
}
151+
func processStr(str:String)->[Int: String]
152+
{
153+
let _token = self.partOfSpeech(str)
154+
for (_index,_value) in _token.enumerate()
155+
{
156+
157+
}
158+
}*/
159+
}

AskFoodDemo/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.088</string>
18+
<string>0.1.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

0 commit comments

Comments
 (0)