Skip to content

Commit

Permalink
Merge pull request #151 from Zolon-DOL/master
Browse files Browse the repository at this point in the history
Sprint 5 changes
  • Loading branch information
pbhatt17 authored Jul 1, 2022
2 parents 604e2c0 + fa888e2 commit 39966c6
Show file tree
Hide file tree
Showing 14 changed files with 488 additions and 117 deletions.
4 changes: 4 additions & 0 deletions Child Labor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
1334AC97283BC372000F647E /* CustomExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1334AC96283BC372000F647E /* CustomExtensions.swift */; };
1334AC992841028D000F647E /* GoodsParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1334AC982841028C000F647E /* GoodsParser.swift */; };
1334AC9B28410338000F647E /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1334AC9A28410338000F647E /* Constants.swift */; };
136829B0286CA84C0083D8E4 /* CustomLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 136829AF286CA84C0083D8E4 /* CustomLabel.swift */; };
13840007282965170072C737 /* ProportionalChartController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13840006282965160072C737 /* ProportionalChartController.swift */; };
139AC81D2332509A002420FF /* North_Macedonia-map.png in Resources */ = {isa = PBXBuildFile; fileRef = 139AC8122332509A002420FF /* North_Macedonia-map.png */; };
139AC81E2332509A002420FF /* Moldova.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 139AC8132332509A002420FF /* Moldova.pdf */; };
Expand Down Expand Up @@ -1145,6 +1146,7 @@
1334AC96283BC372000F647E /* CustomExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomExtensions.swift; sourceTree = "<group>"; };
1334AC982841028C000F647E /* GoodsParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GoodsParser.swift; sourceTree = "<group>"; };
1334AC9A28410338000F647E /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
136829AF286CA84C0083D8E4 /* CustomLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomLabel.swift; sourceTree = "<group>"; };
13840006282965160072C737 /* ProportionalChartController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProportionalChartController.swift; sourceTree = "<group>"; };
139AC8122332509A002420FF /* North_Macedonia-map.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "North_Macedonia-map.png"; sourceTree = "<group>"; };
139AC8132332509A002420FF /* Moldova.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = Moldova.pdf; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2279,6 +2281,7 @@
1334AC772832B76B000F647E /* GoodsChartCollectionCell.swift */,
1334AC782832B76B000F647E /* DataVisualizationTableViewController.swift */,
1334AC792832B76B000F647E /* CirclesLayout.h */,
136829AF286CA84C0083D8E4 /* CustomLabel.swift */,
);
path = charts;
sourceTree = SOURCE_ROOT;
Expand Down Expand Up @@ -4632,6 +4635,7 @@
buildActionMask = 2147483647;
files = (
1334AC97283BC372000F647E /* CustomExtensions.swift in Sources */,
136829B0286CA84C0083D8E4 /* CustomLabel.swift in Sources */,
83EF03A01B4D944E00C2AECE /* GoodsTableViewController.swift in Sources */,
834D8DA71B4C5EFA001CD795 /* StatisticsTableViewController.swift in Sources */,
1334AC7F2832B76B000F647E /* ProportionalChartViewController.swift in Sources */,
Expand Down
Binary file not shown.
20 changes: 15 additions & 5 deletions Child Labor/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -4946,7 +4946,7 @@ Standards </string>
<!--Pakistan -->
<scene sceneID="BiR-BR-knK">
<objects>
<tableViewController title="Pakistan " id="XFU-uo-r1D" customClass="PakistanTableViewController" sceneMemberID="viewController">
<tableViewController title="Pakistan " id="XFU-uo-r1D" customClass="PakistanTableViewController" customModule="Child_Labor" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="none" allowsSelection="NO" rowHeight="44" sectionHeaderHeight="10" sectionFooterHeight="10" id="IfL-2n-4Ge">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -5217,14 +5217,14 @@ Standards </string>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" ambiguous="YES" insetsLayoutMarginsFromSafeArea="NO" text="Punjab" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="gHK-D6-Iqf">
<rect key="frame" x="8" y="10" width="52.5" height="20.5"/>
<rect key="frame" x="16" y="10" width="52.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" ambiguous="YES" insetsLayoutMarginsFromSafeArea="NO" text="Unavailable" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="K15-wq-z9p">
<rect key="frame" x="224.5" y="10" width="87.5" height="20.5"/>
<rect key="frame" x="216.5" y="10" width="87.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand All @@ -5241,14 +5241,14 @@ Standards </string>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" ambiguous="YES" insetsLayoutMarginsFromSafeArea="NO" text="Sindh" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="j9u-vU-4r0">
<rect key="frame" x="8" y="10" width="43.5" height="20.5"/>
<rect key="frame" x="16" y="10" width="43.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" ambiguous="YES" insetsLayoutMarginsFromSafeArea="NO" text="Unavailable" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Uo8-jC-9jP">
<rect key="frame" x="224.5" y="10" width="87.5" height="20.5"/>
<rect key="frame" x="216.5" y="10" width="87.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand Down Expand Up @@ -5493,6 +5493,11 @@ Standards </string>
<outlet property="delegate" destination="XFU-uo-r1D" id="q5b-ir-tUA"/>
</connections>
</tableView>
<connections>
<outlet property="agricultureLabel" destination="pnJ-oR-gbb" id="DpX-Y3-qeu"/>
<outlet property="industryLabel" destination="5c2-Z4-gyj" id="K2f-dC-Ew0"/>
<outlet property="servicesLabel" destination="OLW-ao-zyB" id="VaS-HM-gbR"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Z6U-xv-Mf7" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down Expand Up @@ -5880,6 +5885,11 @@ Standards </string>
<outlet property="delegate" destination="uJa-TJ-kxr" id="hiU-oH-KMo"/>
</connections>
</tableView>
<connections>
<outlet property="agricultureLabel" destination="kLx-jx-9Go" id="4d5-wM-a8R"/>
<outlet property="industryLabel" destination="tw4-Xy-Gix" id="1B1-L1-DnU"/>
<outlet property="servicesLabel" destination="OgV-vB-SOs" id="B2A-zy-TEh"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="rTw-oN-Qgr" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down
142 changes: 131 additions & 11 deletions Child Labor/PakistanTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import UIKit

class PakistanTableViewController: UITableViewController {

var countryName = "Brazil"



var countryName = "Pakistan"

@IBOutlet weak var agricultureLabel: UILabel!
@IBOutlet weak var industryLabel: UILabel!
@IBOutlet weak var servicesLabel: UILabel!

var analyticsData: [Segment] = [Segment]()

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -25,7 +26,11 @@ class PakistanTableViewController: UITableViewController {
tracker?.set(kGAIScreenName, value: "Pakistan Statistics Screen")
tracker?.send(GAIDictionaryBuilder.createAppView().build() as! [AnyHashable: Any])


self.readDataFromXML()
self.addTableViewFooter()
}

func readDataFromXML() {
let urlPath = Bundle.main.path(forResource: "countries_2016", ofType: "xml")
var contents: NSString?
do {
Expand All @@ -36,15 +41,123 @@ class PakistanTableViewController: UITableViewController {
let countriesXML = SWXMLHash.parse(contents! as String)

for country in countriesXML["Countries"]["Country"].all {
if country["Name"].element?.text == "Pakistan"{
if country["Name"].element?.text == "Pakistan" {

let statistics = country["Country_Statistics"]

// Agriculture
if let agriculturePercentage = statistics["Children_Work_Statistics"]["Agriculture"].element {
if agriculturePercentage.text != nil {
if agriculturePercentage.text != "" {
agricultureLabel.text = String(format: "%.1f", (agriculturePercentage.text as NSString).floatValue * 100.0) + "%"
agricultureLabel.textColor = UIColor.black

if (agriculturePercentage.text as NSString).floatValue > 0 {
let agricultureSector = Segment.init(color: UIColor(red: 108.0/255.0, green: 129.0/255.0, blue: 79.0/255.0, alpha: 1), value: CGFloat((agriculturePercentage.text as NSString).floatValue * 100.0), title : "Agriculture", isFloatType: true)
analyticsData.append(agricultureSector)
}
}
}
if (agriculturePercentage.text == "Unavailable" || agriculturePercentage.text == "unavailable")
{
agricultureLabel.text = "Unavailable"
agricultureLabel.textColor = UIColor.black
}
if agriculturePercentage.text == "N/A"
{
agricultureLabel.text = "N/A"
agricultureLabel.accessibilityLabel = "Not Available"
agricultureLabel.textColor = UIColor.black
}

}

// Services
if let servicesPercentage = statistics["Children_Work_Statistics"]["Services"].element {
if servicesPercentage.text != nil {
if servicesPercentage.text != "" {
servicesLabel.text = String(format: "%.1f", (servicesPercentage.text as NSString).floatValue * 100.0) + "%"
servicesLabel.textColor = UIColor.black
if (servicesPercentage.text as NSString).floatValue > 0 {
let servicesSector = Segment.init(color: UIColor(red: 57.0/255.0, green: 89.0/255.0, blue: 122.0/255.0, alpha: 1), value: CGFloat((servicesPercentage.text as NSString).floatValue * 100.0), title : "Services", isFloatType: true)
analyticsData.append(servicesSector)
}
}
}
if (servicesPercentage.text == "Unavailable" || servicesPercentage.text == "unavailable")
{
servicesLabel.text = "Unavailable"
servicesLabel.textColor = UIColor.black
}
if servicesPercentage.text == "N/A"
{
servicesLabel.text = "N/A"
servicesLabel.accessibilityLabel = "Not Available"
servicesLabel.textColor = UIColor.black
}

}

// Industry
if let industryPercentage = statistics["Children_Work_Statistics"]["Industry"].element {
if industryPercentage.text != nil {
if industryPercentage.text != "" {
industryLabel.text = String(format: "%.1f", (industryPercentage.text as NSString).floatValue * 100.0) + "%"
industryLabel.textColor = UIColor.black
if (industryPercentage.text as NSString).floatValue > 0 {
let industrySector = Segment.init(color: UIColor(red: 218.0/255.0, green: 142.0/255.0, blue: 57.0/255.0, alpha: 1), value: CGFloat((industryPercentage.text as NSString).floatValue * 100.0), title : "Industry", isFloatType: true)
analyticsData.append(industrySector)
}
}
}
if (industryPercentage.text == "Unavailable" || industryPercentage.text == "unavailable")
{
industryLabel.text = "Unavailable"
industryLabel.textColor = UIColor.black
}
if industryPercentage.text == "N/A"
{
industryLabel.text = "N/A"
industryLabel.accessibilityLabel = "Not Available"
industryLabel.textColor = UIColor.black
}
}
if #available(iOS 13.0, *) {
servicesLabel.textColor = .label
agricultureLabel.textColor = .label
industryLabel.textColor = .label
} else {
// Fallback on earlier versions
}
break;
}

}
}

func addTableViewFooter() {
let customView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 50))
customView.backgroundColor = UIColor.clear
let button = UIButton(frame: CGRect(x: 20, y: 0, width: self.tableView.frame.width - 40, height: 50))
button.setTitleColor(UIColor.black, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize:20)
button.backgroundColor = .lightGray.withAlphaComponent(0.8)
button.layer.cornerRadius = 20
button.setTitle("Open Analysis", for: .normal)
button.addTarget(self, action: #selector(openWorkingStatics), for: .touchUpInside)
customView.addSubview(button)
self.tableView.tableFooterView = customView

}

@objc func openWorkingStatics(_ sender: UIButton!) {

let viewController = PieChartViewController()
viewController.isFromWorkingStatistics = true
viewController.workingStatistics = analyticsData
viewController.countryName = self.countryName
navigationController?.pushViewController(viewController, animated: true)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
Expand All @@ -53,15 +166,22 @@ class PakistanTableViewController: UITableViewController {
// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1

return 8
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 7
return (section == 0) ? 0 : 3
}

override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
let header = view as! UITableViewHeaderFooterView
header.textLabel?.textColor = UIColor.gray
}

override func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
let header = view as! UITableViewHeaderFooterView
header.textLabel?.textColor = UIColor.gray
}
}

Loading

0 comments on commit 39966c6

Please sign in to comment.