Skip to content

Commit

Permalink
更新营养计算的算法,修正UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Colearo committed Feb 14, 2016
1 parent cdc85b0 commit e06ac20
Show file tree
Hide file tree
Showing 27 changed files with 421 additions and 30 deletions.
Binary file added AF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AppIcon120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AppIcon152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AppIcon167.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AppIcon76.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions AskFoodDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
E43187F01C5A1C1F00F40BFE /* Exten_UIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E43187EF1C5A1C1F00F40BFE /* Exten_UIView.swift */; };
E43189AA1C5A7A6F00F40BFE /* Charts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E43189A51C5A7A4600F40BFE /* Charts.framework */; };
E43189AB1C5A7A6F00F40BFE /* Charts.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E43189A51C5A7A4600F40BFE /* Charts.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
E4C71ED01C5E2B5500A6FEB6 /* Protein.pdf in Resources */ = {isa = PBXBuildFile; fileRef = E4C71ECF1C5E2B5500A6FEB6 /* Protein.pdf */; };
E4C71ED21C5E4A0F00A6FEB6 /* VC_c_s.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4C71ED11C5E4A0F00A6FEB6 /* VC_c_s.swift */; };
E4EC222E1C5CDD3700E6D7C9 /* FoodPro.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4EC222D1C5CDD3600E6D7C9 /* FoodPro.swift */; };
/* End PBXBuildFile section */

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

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -172,6 +178,7 @@
E43187A41C59F7CC00F40BFE /* ViewController.swift */,
E43187C21C59F8F900F40BFE /* Color.swift */,
E43187A61C59F7CC00F40BFE /* Main.storyboard */,
E4C71ED11C5E4A0F00A6FEB6 /* VC_c_s.swift */,
E43187D71C5A098500F40BFE /* VC_c.swift */,
E43187D51C5A08CC00F40BFE /* VC_b.swift */,
E43187D31C5A071F00F40BFE /* VC_a.swift */,
Expand Down Expand Up @@ -201,6 +208,7 @@
E43187E91C5A156400F40BFE /* MessageBubble@2x.png */,
E43187C51C59F9A700F40BFE /* button1.pdf */,
E43187C61C59F9A700F40BFE /* button2.pdf */,
E4C71ECF1C5E2B5500A6FEB6 /* Protein.pdf */,
E43187C71C59F9A700F40BFE /* button3.pdf */,
E43187C81C59F9A700F40BFE /* logo1.pdf */,
E43187C91C59F9A700F40BFE /* logos.pdf */,
Expand All @@ -216,6 +224,7 @@
E43187DA1C5A0CC200F40BFE /* NavigationDelegate.swift */,
E43187DC1C5A0D8500F40BFE /* CiecleAnimation.swift */,
E43188331C5A7A4600F40BFE /* Charts */,
E4EC222D1C5CDD3600E6D7C9 /* FoodPro.swift */,
);
name = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -368,6 +377,7 @@
E43187EC1C5A15D500F40BFE /* Me.png in Resources */,
E43187AA1C59F7CC00F40BFE /* Assets.xcassets in Resources */,
E43187EA1C5A156400F40BFE /* MessageBubble@2x.png in Resources */,
E4C71ED01C5E2B5500A6FEB6 /* Protein.pdf in Resources */,
E43187CD1C59F9A700F40BFE /* logo1.pdf in Resources */,
E43187CB1C59F9A700F40BFE /* button2.pdf in Resources */,
E43187CC1C59F9A700F40BFE /* button3.pdf in Resources */,
Expand Down Expand Up @@ -400,9 +410,11 @@
E43187A31C59F7CC00F40BFE /* AppDelegate.swift in Sources */,
E43187D61C5A08CC00F40BFE /* VC_b.swift in Sources */,
E43187F01C5A1C1F00F40BFE /* Exten_UIView.swift in Sources */,
E4C71ED21C5E4A0F00A6FEB6 /* VC_c_s.swift in Sources */,
E43187D21C59FD4200F40BFE /* VC2.swift in Sources */,
E43187E21C5A151100F40BFE /* TableHeaderViewCell.swift in Sources */,
E43187E81C5A154D00F40BFE /* MessageItem.swift in Sources */,
E4EC222E1C5CDD3700E6D7C9 /* FoodPro.swift in Sources */,
E43187D01C59FA5100F40BFE /* VC1.swift in Sources */,
E43187DB1C5A0CC200F40BFE /* NavigationDelegate.swift in Sources */,
E43187C31C59F8F900F40BFE /* Color.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "AskFoodDemo/FoodPro.swift"
timestampString = "475917094.579383"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "46"
endingLineNumber = "46"
landmarkName = "computNutri(_:Sexof:Intensity:Time:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions AskFoodDemo/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"idiom" : "iphone",
"filename" : "AppIcon120.png",
"scale" : "2x"
},
{
Expand Down Expand Up @@ -51,18 +52,21 @@
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"idiom" : "ipad",
"filename" : "AppIcon76.png",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"idiom" : "ipad",
"filename" : "AppIcon152.png",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "AppIcon167.png",
"scale" : "2x"
}
],
Expand Down
21 changes: 21 additions & 0 deletions AskFoodDemo/Assets.xcassets/Protein.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Protein.pdf",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
30 changes: 27 additions & 3 deletions AskFoodDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Srg-7m-Z6h" userLabel="First Responder" sceneMemberID="firstResponder"/>
<customObject id="gfi-lu-SmH" customClass="NavigationControllerDelegate" customModule="AskFoodDemo" customModuleProvider="target"/>
<customObject id="gfi-lu-SmH" customClass="NavigationControllerDelegate" customModule="AskFoodDemo" customModuleProvider="target">
<connections>
<outlet property="navigationController" destination="xfy-Uo-QSH" id="qeQ-Iw-SDi"/>
</connections>
</customObject>
</objects>
<point key="canvasLocation" x="948" y="316"/>
</scene>
Expand Down Expand Up @@ -277,12 +281,32 @@
</view>
<connections>
<outlet property="Button" destination="Pee-JW-09c" id="b0p-SK-8KI"/>
<segue destination="vvo-E5-n7a" kind="show" identifier="toAbout" action="showDetailViewController:sender:" id="Gdn-LE-klI"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="QtW-6W-CGc" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2307" y="1727"/>
</scene>
<!--c s-->
<scene sceneID="2nM-rd-2sk">
<objects>
<viewController id="vvo-E5-n7a" customClass="VC_c_s" customModule="AskFoodDemo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="CsD-29-i1B"/>
<viewControllerLayoutGuide type="bottom" id="2qa-GU-DqZ"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="uTq-3S-SXp">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.94509803920000002" green="0.2901960784" blue="0.20784313730000001" alpha="1" colorSpace="calibratedRGB"/>
<gestureRecognizers/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="rqM-cr-zGd" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2967" y="1727"/>
</scene>
<!--a-->
<scene sceneID="ofx-v5-SGy">
<objects>
Expand Down Expand Up @@ -312,12 +336,12 @@
<action selector="ClickBtn:" destination="LMN-Cg-nXG" eventType="touchUpInside" id="btU-0s-rcU"/>
</connections>
</button>
<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">
<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">
<rect key="frame" x="20" y="38" width="136" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FyY-kP-1Fq">
<button hidden="YES" opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FyY-kP-1Fq">
<rect key="frame" x="203" y="38" width="46" height="30"/>
<state key="normal" title="Button"/>
<connections>
Expand Down
2 changes: 1 addition & 1 deletion AskFoodDemo/CiecleAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CircleTransitionAnimatorPopA: NSObject, UIViewControllerAnimatedTransition
//containerView!.addSubview(toViewController.view)
containerView!.insertSubview(toView, aboveSubview: fromView)
// 4
let circleMaskPathInitial = UIBezierPath(ovalInRect: button.frame)
let circleMaskPathInitial = UIBezierPath(ovalInRect: VC_A_Frame!)
let extremePoint = CGPointMake(button.center.x, button.center.y - CGRectGetHeight(toView.bounds)) // need more research
let radius = sqrt(extremePoint.x * extremePoint.x + extremePoint.y * extremePoint.y)
let circleMaskPathFinal = UIBezierPath(ovalInRect: CGRectInset(button.frame, -radius, -radius))
Expand Down
159 changes: 159 additions & 0 deletions AskFoodDemo/FoodPro.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
//
// FoodPro.swift
// AskFoodDemo
//
// Created by Colearo on 16/1/30.
// Copyright © 2016年 Colearo. All rights reserved.
//

import Foundation
enum Sex{
case Female
case Male
}
enum LabourIntensity{
case Small,Middle,High
}
enum TimeDur{
case Morning,Noon,Night
}
enum ReturnStyle{
case Input,Button
}
class nutrition {
private let EER:[Sex: [LabourIntensity: [Int: Double]]] = [
.Male: [
.Small: [18: 2250,50: 2100,65: 2050,8: 1650,9: 1750,10: 1800,11: 2050,14: 2500],
.Middle: [18: 2600,50: 2450,65: 2350,8: 1850,9: 2000,10: 2050,11: 2350,14:2850],
.High: [18: 3000,50: 2800,8: 2100,9: 2250,10: 2300,11: 2600,14: 3200]
],
.Female: [.Small: [8: 1450,9: 1550,10: 1650,11: 1800,14: 2000,18: 1800,50: 1750,65: 1700],
.Middle: [8: 1700,9: 1800,10: 1900,11: 2050,14: 2300,18: 2100,50: 2050,65: 1950],
.High: [8: 1900,9: 2000,10: 2150,11: 2300,14: 2550,18: 2400,50: 2350]
]
]
private let PRO:[Sex: [Int: Double]] = [.Female: [8: 40,9: 45,10: 50,11: 55,14: 60,18: 55],
.Male: [8: 40,9: 45,10: 50,11: 60,14: 75,18: 65]]
private let CHO:[Int: Double] = [1: 120,11: 150,18: 120]
private let Ca:[Int: Double] = [7: 1000,11: 1200,14: 1000,18: 800,50: 1000]
private let Vc:Double=100
func computNutri(Age: Int,Sexof: Sex,Intensity: LabourIntensity,Time: TimeDur)->(Vc:Double,Ca:Double,CHO: Double,Fat: Double,EER: Double,PRO: Double)
{
var _EER=0.0,_PRO=0.0,_CHO=0.0,_Ca=0.0,_Vc=0.0,_Fat=0.0
if Age>8 && Age<=11{
_EER=self.EER[Sexof]![Intensity]![Age]!
_Ca=((Age==11) ? self.Ca[Age] : self.Ca[7])!
_CHO=self.CHO[1]!
_PRO=self.PRO[Sexof]![Age]!
}
else if Age>11 && Age<14{
_EER=self.EER[Sexof]![Intensity]![11]!
_Ca=self.Ca[11]!
_CHO=self.CHO[11]!
_PRO=self.PRO[Sexof]![11]!
}
else if Age>=14 && Age<18{
_EER=self.EER[Sexof]![Intensity]![14]!
_Ca=self.Ca[14]!
_CHO=self.CHO[11]!
_PRO=self.PRO[Sexof]![14]!
}
else if Age>=18 && Age<50{
_EER=self.EER[Sexof]![Intensity]![18]!
_Ca=self.Ca[18]!
_CHO=self.CHO[18]!
_PRO=self.PRO[Sexof]![18]!
}
else if Age>=50 {
_EER=self.EER[Sexof]![Intensity]![50]!
_Ca=self.Ca[50]!
_CHO=self.CHO[18]!
_PRO=self.PRO[Sexof]![18]!
}
_Fat=_EER*0.25/9
_Vc=self.Vc
switch Time
{
case .Morning , .Night:
_Vc*=0.3
_EER*=0.3
_Ca*=0.3
_CHO*=0.3
_Fat*=0.3
_PRO*=0.3
case .Noon:
_Vc*=0.4
_EER*=0.4
_Ca*=0.4
_CHO*=0.4
_Fat*=0.4
_PRO*=0.4
}
return (_Vc,_Ca,_CHO,_Fat,_EER,_PRO)
}

}
class askChat {
private var openTime:NSDate
private var chatStr:String?
private var isAsked:[TimeDur: Bool]
private var inputORbutton:ReturnStyle
typealias TaggedToken = (String, String?)
private let stopWord:[String]=["","","已经","别说","但是","","","况且","哪怕","","","","","","","","还是","当然","到底","",""]
private let countWord:[String]=["","","","","","","","","","","","十几","","一些"]
//private let
func tagT(text: String, scheme: String) -> [String] {
let options: NSLinguisticTaggerOptions = [.OmitWhitespace, .OmitPunctuation, .OmitOther]
let tagger = NSLinguisticTagger(tagSchemes: NSLinguisticTagger.availableTagSchemesForLanguage("en"),
options: Int(options.rawValue))
tagger.string = text
var tokens: [String] = []
// Using NSLinguisticTagger
tagger.enumerateTagsInRange(NSMakeRange(0, text.characters.count), scheme:scheme, options: options) { tag, tokenRange, _, _ in
let token = (text as NSString).substringWithRange(tokenRange)
for stop in self.stopWord{
if token != stop{
tokens.append(token)
}
}
}
return tokens
}
func partOfSpeech(text: String) -> [String] {
return tagT(text,scheme: NSLinguisticTagSchemeNameTypeOrLexicalClass)
}
init(){
self.openTime=NSDate()
self.isAsked=[.Morning: false,.Noon: false,.Night: false]
self.inputORbutton = .Button
}
func judgeTime()->TimeDur
{
let date=NSDateFormatter()
self.openTime=NSDate()
date.dateFormat="HH"
let hour=Int(date.stringFromDate(openTime))
if hour<=11{
return .Morning
}
else if hour>=11&&hour<=16{
return .Noon
}
else if hour>=17&&hour<=24{
return .Night
}
return .Morning
}
/*func getReturned()->(strings:[String],returnsty:ReturnStyle)
{

}
func processStr(str:String)->[Int: String]
{
let _token = self.partOfSpeech(str)
for (_index,_value) in _token.enumerate()
{

}
}*/
}
2 changes: 1 addition & 1 deletion AskFoodDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.088</string>
<string>0.1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
Loading

0 comments on commit e06ac20

Please sign in to comment.