Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/highest renting for appartements #69

Open
wants to merge 184 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
184 commits
Select commit Hold shift + click to select a range
2b92e42
add test directory
MahmoudElshahatt Feb 6, 2023
b5e65fa
add Test package
MahmoudElshahatt Feb 9, 2023
dbe2af7
Prepare for testing
Eng-Light Feb 10, 2023
2b3395f
add GetCheapestBananaPricesCitiesNamesInteractor class
MahmoudElshahatt Feb 10, 2023
512cd0a
setup GetCheapestBananaPricesCitiesNamesInteractor class
MahmoudElshahatt Feb 10, 2023
7864ac9
add GetCheapestBananaPricesCitiesNamesInteractorTest class
MahmoudElshahatt Feb 10, 2023
f857cee
migration with kotlinFixtures
Eng-Light Feb 10, 2023
f460142
implement test cases
Eng-Light Feb 10, 2023
dd4f343
I created a new class for the task of the five best cities to buy clo…
mahmouddeif Feb 10, 2023
a96ddd0
Add class GetTenCitiesHaveTheAverageOfFruitsAndVegetablesPricesIntera…
MennaAkram Feb 10, 2023
ebc3608
I created test class for function task of the five best cities to buy…
mahmouddeif Feb 10, 2023
9cded71
I created test class for function task of the five best cities to buy…
mahmouddeif Feb 10, 2023
cc67949
Merge pull request #3 from MahmoudElshahatt/feature_get_cheapest_ten_…
MahmoudElshahatt Feb 10, 2023
e78ed74
Merge pull request #1 from MahmoudElshahatt/feature/cheapest-banana-p…
MahmoudElshahatt Feb 10, 2023
234082b
Add class GetTenCitiesHaveTheAverageOfFruitsAndVegetablesPricesIntera…
MennaAkram Feb 10, 2023
4bb31c8
Merge remote-tracking branch 'origin/develop' into feature/average-of…
MennaAkram Feb 10, 2023
9e4f8f7
Merge branch 'develop' into feature_get_ten_cities_for_clothes
mahmouddeif Feb 10, 2023
1ff30ed
add class GetHighestCarbonatedDrinksPricesInteractor with test
kareem-01 Feb 10, 2023
3720323
Add Class GetCityNameAndSalrayAverageInteractor
nahedshehata Feb 10, 2023
0f30c08
add test cases
MennaAkram Feb 10, 2023
6928fa0
add implementation for the logic
MennaAkram Feb 11, 2023
a99fc8f
setup GetCheapestBananaPricesCitiesNamesInteractor
MahmoudElshahatt Feb 11, 2023
b95e1a3
add some test cases
kareem-01 Feb 11, 2023
9383c89
implement function execute()
Eng-Light Feb 11, 2023
96d49f9
add kotlin fixture dependency
MahmoudElshahatt Feb 11, 2023
455f3a1
Merge pull request #9 from MahmoudElshahatt/feature/get-cheapest-ten-…
MahmoudElshahatt Feb 11, 2023
9d5e464
Merge remote-tracking branch 'origin/develop' into feature/cheapest-b…
MahmoudElshahatt Feb 11, 2023
0dff7a3
add GetCheapestBananaPricesCitiesNamesInteractor test cases
MahmoudElshahatt Feb 11, 2023
69a72bf
Merge pull request #8 from MahmoudElshahatt/feature/cheapest-banana-p…
MahmoudElshahatt Feb 11, 2023
6d5960d
Merge remote-tracking branch 'origin/develop' into feature_get_ten_ci…
mahmouddeif Feb 11, 2023
075827d
implemented execute function
kareem-01 Feb 11, 2023
b6c5c4a
code enhancements.
Eng-Light Feb 12, 2023
3eac61e
add test cases
MahmoudElshahatt Feb 12, 2023
209f96d
Merge pull request #13 from MahmoudElshahatt/feature/cheapest-banana-…
MahmoudElshahatt Feb 12, 2023
d2bf7ca
create feature class
Shehab-m Feb 12, 2023
19caa28
code enhancements.
Eng-Light Feb 12, 2023
3e27090
Merge branch 'develop' into feature/get-cheapest-ten-cities-apartments
MahmoudElshahatt Feb 12, 2023
19f631d
Update FakeDataSource.kt
MahmoudElshahatt Feb 12, 2023
ede1bea
Merge pull request #12 from MahmoudElshahatt/feature/get-cheapest-ten…
MahmoudElshahatt Feb 12, 2023
11558e6
resolve conflict
Eng-Light Feb 12, 2023
ccb38ce
Merge pull request #15 from MahmoudElshahatt/feature/get-cheapest-ten…
MahmoudElshahatt Feb 12, 2023
793b92b
pass first test
MahmoudElshahatt Feb 12, 2023
beab76b
Merge remote-tracking branch 'origin/develop' into feature/cheapest-b…
MahmoudElshahatt Feb 12, 2023
5c2b5c8
change empty error message
MahmoudElshahatt Feb 12, 2023
63f6ffc
implemented execute function
kareem-01 Feb 12, 2023
94eaec5
pass test case
MahmoudElshahatt Feb 12, 2023
c4f5257
Merge remote-tracking branch 'origin/develop' into feature/get-highes…
kareem-01 Feb 12, 2023
25f1538
create class hardcoded fake datasource
Shehab-m Feb 12, 2023
ca98f70
enhancement
kareem-01 Feb 12, 2023
f8c2a62
Delete kotlinc.xml
MahmoudElshahatt Feb 12, 2023
32c0361
Delete misc.xml
MahmoudElshahatt Feb 12, 2023
fb942a8
Delete build.gradle.kts
MahmoudElshahatt Feb 12, 2023
4510f97
Delete local.properties
MahmoudElshahatt Feb 12, 2023
8dce816
Delete .name
MahmoudElshahatt Feb 12, 2023
c429490
create test class hardcoded fake datasourc
Shehab-m Feb 12, 2023
e08fa3b
pass test case 2
MahmoudElshahatt Feb 12, 2023
f42cb36
pass test case 2
MahmoudElshahatt Feb 12, 2023
cad0f91
pass test case 3
MahmoudElshahatt Feb 12, 2023
fde2fc3
prepare test cases
ahmedfikry24 Feb 12, 2023
cf310c6
Merge branch 'develop' into feature/average-of-fruit-and-vegetables-p…
MennaAkram Feb 12, 2023
4be9e96
update test class hardcoded fake datasource
Shehab-m Feb 12, 2023
ce87733
update feature class
Shehab-m Feb 12, 2023
9af48b3
update test class
Shehab-m Feb 12, 2023
96181a0
delete unnecessary test
MahmoudElshahatt Feb 12, 2023
bf1ff38
add new test case
MennaAkram Feb 12, 2023
aa63088
enhancement
kareem-01 Feb 12, 2023
983a14b
Revert "Delete build.gradle.kts"
kareem-01 Feb 12, 2023
229b91c
Revert "Delete .name"
kareem-01 Feb 12, 2023
4ccbf99
Revert "Delete local.properties"
kareem-01 Feb 12, 2023
a4aa870
Delete .name
MahmoudElshahatt Feb 12, 2023
92584c7
Delete build.gradle.kts
MahmoudElshahatt Feb 12, 2023
79ef83d
Delete local.properties
MahmoudElshahatt Feb 12, 2023
273d07d
Merge pull request #18 from MahmoudElshahatt/feature/get-highest-carb…
MahmoudElshahatt Feb 12, 2023
121b372
Merge pull request #16 from MahmoudElshahatt/feature/cheapest-banana-…
MahmoudElshahatt Feb 12, 2023
62e5c9f
Revert "feature/cheapest banana prices"
MahmoudElshahatt Feb 12, 2023
cfed2bf
Revert "Feature/get highest carbonated drinks prices"
MahmoudElshahatt Feb 12, 2023
880b244
Merge pull request #19 from MahmoudElshahatt/revert-16-feature/cheape…
MahmoudElshahatt Feb 12, 2023
66a9ecb
Merge pull request #20 from MahmoudElshahatt/revert-18-feature/get-hi…
MahmoudElshahatt Feb 12, 2023
097d8e7
Add files via upload
MahmoudElshahatt Feb 12, 2023
f9e47f8
Merge pull request #21 from MahmoudElshahatt/feature/get_city_manager…
MahmoudElshahatt Feb 12, 2023
b2b7519
update cheapest banana prices
MahmoudElshahatt Feb 12, 2023
21909d3
update class hardcoded fake datasource
Shehab-m Feb 12, 2023
a62d22d
setup GetCheapestBananaPricesCitiesNamesInteractorTest class
MahmoudElshahatt Feb 12, 2023
d6485ab
Merge pull request #23 from MahmoudElshahatt/feature/get-cheapest-ban…
MahmoudElshahatt Feb 12, 2023
60cf030
setup GetCheapestBananaPricesCitiesNamesInteractorTest methods
MahmoudElshahatt Feb 12, 2023
b04a956
setup test cases
MahmoudElshahatt Feb 12, 2023
26942b8
pass test case 1
MahmoudElshahatt Feb 12, 2023
4fb8277
pass test case 2 ,3
MahmoudElshahatt Feb 12, 2023
92002cb
Merge pull request #24 from MahmoudElshahatt/feature/get-cheapest-ban…
MahmoudElshahatt Feb 12, 2023
1b7b6a8
improve function implementation
MennaAkram Feb 12, 2023
568d82a
update test class cases
Shehab-m Feb 12, 2023
acc38de
Merge pull request #14 from MahmoudElshahatt/feature/most-suitable-ci…
MahmoudElshahatt Feb 12, 2023
e5a5d9c
Merge pull request #5 from MahmoudElshahatt/feature/average-of-fruit-…
MahmoudElshahatt Feb 12, 2023
52ca53e
implement execute & all tests passes
kareem-01 Feb 12, 2023
50401f2
Merge remote-tracking branch 'origin/feature/get-highest-carbonated-d…
kareem-01 Feb 12, 2023
9fab6a0
create function class
mahmouddeif Feb 12, 2023
45c848f
update a comment
MahmoudElshahatt Feb 12, 2023
89f5364
Merge remote-tracking branch 'origin/develop' into feature/get-five-c…
mahmouddeif Feb 12, 2023
73d10bf
test the function in the main
MennaAkram Feb 12, 2023
9ecbb9c
Merge remote-tracking branch 'origin/develop' into feature/city_name_…
nahedshehata Feb 12, 2023
60b99c1
tested main
kareem-01 Feb 13, 2023
20bf893
create test cases
ahmedfikry24 Feb 13, 2023
431ef4f
update feature class with functions implementation
Shehab-m Feb 13, 2023
209e7be
update main with feature class object and println function output
Shehab-m Feb 13, 2023
3d9f841
create class logic
ahmedfikry24 Feb 13, 2023
76e37aa
change function impl
MahmoudElshahatt Feb 13, 2023
89f62ed
Merge pull request #28 from MahmoudElshahatt/feature/get-cheapest-ban…
MahmoudElshahatt Feb 13, 2023
81166aa
resolve conflict
kareem-01 Feb 13, 2023
8b6f92c
added function for countries
kareem-01 Feb 13, 2023
bc50336
Merge remote-tracking branch 'origin/develop' into feature/get_city_m…
ahmedfikry24 Feb 13, 2023
479f864
Merge remote-tracking branch 'origin/develop' into feature/get-five-c…
mahmouddeif Feb 13, 2023
3265785
add test cases
Alaakhaled101 Feb 13, 2023
309fe26
fixed issues with the result
kareem-01 Feb 13, 2023
0eac134
Merge remote-tracking branch 'origin/develop' into feature/get-highes…
MahmoudElshahatt Feb 13, 2023
77a29d7
Merge pull request #26 from MahmoudElshahatt/feature/get-highest-carb…
MahmoudElshahatt Feb 13, 2023
e719ff2
Merge remote-tracking branch 'origin/feature/get-highest-carbonated-d…
kareem-01 Feb 13, 2023
82163b6
Merge pull request #27 from MahmoudElshahatt/feature/most-suitable-ci…
MahmoudElshahatt Feb 13, 2023
d8ac39b
add test cases
nahedshehata Feb 13, 2023
7a0a4cd
delete comments
MahmoudElshahatt Feb 13, 2023
44df68c
Merge branch 'develop' into feature/get-highest-carbonated-drinks-prices
MahmoudElshahatt Feb 13, 2023
9d2af1e
Merge pull request #30 from MahmoudElshahatt/feature/internet-connect…
MahmoudElshahatt Feb 13, 2023
329e7a9
Merge pull request #31 from MahmoudElshahatt/feature/city_name_and_sa…
MahmoudElshahatt Feb 13, 2023
cd8a1f5
Merge remote-tracking branch 'origin/develop' into feature/get-highes…
MahmoudElshahatt Feb 13, 2023
e4a497a
Merge pull request #29 from MahmoudElshahatt/feature/get-highest-carb…
MahmoudElshahatt Feb 13, 2023
57b53ff
Revert "feature/average of fruit and vegetables prices"
MahmoudElshahatt Feb 13, 2023
1e217c7
Merge pull request #33 from MahmoudElshahatt/revert-5-feature/average…
MahmoudElshahatt Feb 13, 2023
74f0219
create function class
mahmouddeif Feb 13, 2023
abe53b7
refactor
MahmoudElshahatt Feb 13, 2023
755d9a3
Merge remote-tracking branch 'origin/develop' into feature/average-of…
MennaAkram Feb 13, 2023
d8fec62
refactor
MahmoudElshahatt Feb 13, 2023
e13d3d6
add function GetCityHasCheapestInternetConnectionInteractor execute
Alaakhaled101 Feb 13, 2023
ffaa037
update the test cases and the implementation
MennaAkram Feb 13, 2023
8e7207b
add implemention function
nahedshehata Feb 13, 2023
3c5eb69
add implemention function and edit
nahedshehata Feb 14, 2023
0323e43
Merge remote-tracking branch 'origin/develop' into feature/get_city_m…
ahmedfikry24 Feb 14, 2023
2e53d84
Merge pull request #32 from MahmoudElshahatt/feature/average-of-fruit…
MahmoudElshahatt Feb 14, 2023
8f8361f
refactor class logic
ahmedfikry24 Feb 14, 2023
f436395
Merge branch 'develop' into feature/get-five-cities-for-clothes
MahmoudElshahatt Feb 14, 2023
f2c00f9
Delete local.properties
MahmoudElshahatt Feb 14, 2023
d6accd8
add printSeparationLine
MahmoudElshahatt Feb 14, 2023
02c996b
Delete gradle.xml
MahmoudElshahatt Feb 14, 2023
cf67e00
Delete local.properties
MahmoudElshahatt Feb 14, 2023
8665cf5
Update HardCodedFakeDataSource.kt
Eng-Light Feb 14, 2023
0c5f011
Update GetCityHasCheapestInternetConnectionInteractor.kt
Eng-Light Feb 14, 2023
6f4193b
update class hardcoded fake datasource add mixedCityList
Shehab-m Feb 14, 2023
6e5834e
update test class cases add new case
Shehab-m Feb 14, 2023
65c35d8
update testcases
nahedshehata Feb 14, 2023
8c60869
Delete Main.kt
MahmoudElshahatt Feb 14, 2023
3436aa9
Merge pull request #34 from MahmoudElshahatt/feature/get_city_manager…
MahmoudElshahatt Feb 14, 2023
50dc9ff
Merge branch 'develop' into feature/most-suitable-city-for-more-savin…
Eng-Light Feb 14, 2023
1746416
Merge pull request #38 from MahmoudElshahatt/feature/most-suitable-ci…
MahmoudElshahatt Feb 14, 2023
df03c7e
Merge pull request #35 from MahmoudElshahatt/feature/internet-connect…
MahmoudElshahatt Feb 14, 2023
cae244f
Update HardCodedFakeDataSource.kt
MahmoudElshahatt Feb 14, 2023
430094f
Update GetCityHasCheapestInternetConnectionInteractor.kt
MahmoudElshahatt Feb 14, 2023
e7dd73c
Update GetCityHasCheapestInternetConnectionInteractorTest.kt
MahmoudElshahatt Feb 14, 2023
17999f0
Update GetCityHasCheapestInternetConnectionInteractorTest.kt
MahmoudElshahatt Feb 14, 2023
2c10a0a
Merge pull request #36 from MahmoudElshahatt/feature/get-five-cities-…
MahmoudElshahatt Feb 14, 2023
c9697c6
code refactor
MahmoudElshahatt Feb 14, 2023
d00ef21
Merge branch 'develop' into feature/city_name_and_salary_ave
MahmoudElshahatt Feb 14, 2023
93139fb
Merge pull request #37 from MahmoudElshahatt/feature/city_name_and_sa…
MahmoudElshahatt Feb 14, 2023
84c2415
add testcases
febronia53 Feb 14, 2023
d16e888
add function implementation
febronia53 Feb 14, 2023
9318b4f
Merge pull request #39 from MahmoudElshahatt/feature/highest-renting-…
MahmoudElshahatt Feb 14, 2023
17c940b
update class names
MahmoudElshahatt Feb 14, 2023
3b1d343
refactor main function
MahmoudElshahatt Feb 14, 2023
4c8ed3c
update test class implementation remove run scope
Shehab-m Feb 16, 2023
993b36d
update feature class implementation add scope functions and constants
Shehab-m Feb 16, 2023
c625b5b
enhance GetCheapestBananaPricesCitiesNamesInteractor
MahmoudElshahatt Feb 17, 2023
7200ce2
setup main
MahmoudElshahatt Feb 17, 2023
c0d3358
refactor test cases
MahmoudElshahatt Feb 17, 2023
bd00829
Enhance logic of the class
febronia53 Feb 18, 2023
158140d
refactor GetCheapestApartmentsCitiesNamesInteractor.kt
Eng-Light Feb 18, 2023
1785e5e
update feature class execute function implementation
Shehab-m Feb 18, 2023
ed8f838
update feature class functions implementation add scope functions in …
Shehab-m Feb 18, 2023
8558b19
add constants
Eng-Light Feb 18, 2023
9041b4d
Merge pull request #45 from MahmoudElshahatt/fix/get-cheapest-banana-…
MahmoudElshahatt Feb 18, 2023
22f48c7
Merge branch 'develop' into fix/get-cheapest-ten-cities-apartments
MahmoudElshahatt Feb 18, 2023
b5751c1
Merge pull request #46 from MahmoudElshahatt/fix/get-cheapest-ten-cit…
MahmoudElshahatt Feb 18, 2023
d2a9a81
Merge pull request #43 from MahmoudElshahatt/fix/most-suitable-city-f…
MahmoudElshahatt Feb 18, 2023
173c0ce
update test class comments
Shehab-m Feb 18, 2023
f9b6007
Merge pull request #54 from MahmoudElshahatt/fix/most-suitable-city-f…
MahmoudElshahatt Feb 19, 2023
748a483
Merge pull request #50 from MahmoudElshahatt/fix/highest-renting-for-…
MahmoudElshahatt Feb 19, 2023
533e9ac
enhance test class comments' in "get city has highest renting"
febronia53 Feb 19, 2023
49a3750
Update GetCityHasHighestRentingBetweenApartmentsInteractorTest.kt
febronia53 Feb 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .idea/gradle.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/misc.xml

This file was deleted.

2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ repositories {

dependencies {
testImplementation(kotlin("test"))
testImplementation("com.appmattus.fixture:fixture:1.2.0")
testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
Expand Down
53 changes: 47 additions & 6 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import dataSource.CsvDataSource
import dataSource.utils.CsvParser
import interactor.CostOfLivingDataSource
import interactor.GetCityHasCheapestInternetConnectionInteractor
import interactor.GetHighestSalaryAverageCititesNamesInteractor
import interactor.*

fun main() {
val csvParser = CsvParser()
Expand All @@ -12,11 +10,54 @@ fun main() {
println(getHighestSalaryAverageCities.execute(limit = 10))
printSeparationLine()

val getTenCitiesHaveTheAverageOfFruitsAndVegetablesPrices =
GetTenCitiesHaveTheAverageOfFruitsAndVegetablesPricesInteractor(dataSource)
println(getTenCitiesHaveTheAverageOfFruitsAndVegetablesPrices.execute())
printSeparationLine()

val getCheapestApartmentsCitiesNamesInteractor = GetCheapestApartmentsCitiesNamesInteractor(dataSource)
getCheapestApartmentsCitiesNamesInteractor.execute(10, 100).forEach {
println("Number of years needed to buy a 100m apartment in ${it.first} city is : " + "%.2f".format(it.second))
}
printSeparationLine()

val getCityHasCheapestInternetConnectionInteractor = GetCityHasCheapestInternetConnectionInteractor(dataSource)
println(getCityHasCheapestInternetConnectionInteractor.execute())
println(getCityHasCheapestInternetConnectionInteractor.execute(1))
printSeparationLine()

val getCheapestBananaPricesCitiesNamesInteractor=GetCheapestBananaPricesCitiesNamesInteractor(dataSource)
getCheapestBananaPricesCitiesNamesInteractor.apply {
println(execute(*getCitiesVarArgs().toTypedArray()))
}
printSeparationLine()

val getBestClothesPriceCitiesNameInteractor =
GetTopFiveCitiesNamesForShoppingClothesFromFamousBrandsInteractor(dataSource)
println(getBestClothesPriceCitiesNameInteractor.execute(limit = 5))
printSeparationLine()

val getCityNameAndSalaryAverageInteractor = GetCityNameAndSalrayAverageInteractor(dataSource)
println(getCityNameAndSalaryAverageInteractor.execute("Egypt"))
printSeparationLine()

val getMostSuitableCityForMoreSavingsPerMonthInteractor =
GetMostSuitableCityForMoreSavingsPerMonthInteractor(dataSource)
getMostSuitableCityForMoreSavingsPerMonthInteractor.apply {
println(execute())
}
printSeparationLine()

val getCityManagerExpectationInteractor = GetCityManagerExpectationInteractor(dataSource)
println(getCityManagerExpectationInteractor.execute())
printSeparationLine()

val getCityHasHighestRentingBetweenApartmentsInteractor =
GetCityHasHighestRentingBetweenApartmentsInteractor(dataSource)
println("The City has highest renting between apartements inside city center and outside is: "
+getCityHasHighestRentingBetweenApartmentsInteractor.execute().cityName)

}
private fun printSeparationLine(){

private fun printSeparationLine() {
print("\n_______________________________\n")
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package interactor

import model.CityEntity

class GetCheapestApartmentsCitiesNamesInteractor(
private val dataSource: CostOfLivingDataSource
) {

object Const {
const val MONTHS_OF_THE_YEAR = 12
}

fun execute(limit: Int, meters: Int): List<Pair<String, Float>> {

return dataSource.getAllCitiesData()
.excludeNullSalariesNullPricesAndLowQualityData()
.sortedByDescending {
it.averageMonthlyNetSalaryAfterTax!! /
it.realEstatesPrices.pricePerSquareMeterToBuyApartmentOutsideOfCentre!!
}
.take(limit)
.map { Pair(it.cityName, it.calculateNumberOfYears(meters)) }
.takeIf { it.isNotEmpty() && it.size == limit }
?: listOf(
Pair("Couldn't find Cities that meet your requirements :(", 0.0f)
)
}

private fun List<CityEntity>.excludeNullSalariesNullPricesAndLowQualityData(): List<CityEntity> {
return this.filter {
it.realEstatesPrices.pricePerSquareMeterToBuyApartmentOutsideOfCentre != null &&
it.averageMonthlyNetSalaryAfterTax != null &&
it.dataQuality
}
}

/*
Calculate how many years needed to buy 100meter apartment outSide center of the city
depending on monthly salary and squareMeter's price.
*/
private fun CityEntity.calculateNumberOfYears(meters: Int): Float {
return this.realEstatesPrices.pricePerSquareMeterToBuyApartmentOutsideOfCentre!! * meters /
(this.averageMonthlyNetSalaryAfterTax!! * Const.MONTHS_OF_THE_YEAR)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package interactor

import model.CityEntity

class GetCheapestBananaPricesCitiesNamesInteractor(
private val dataSource: CostOfLivingDataSource
) {
fun getCitiesVarArgs(): List<CityEntity> {
return dataSource.getAllCitiesData()
}

fun execute(vararg cityEntities: CityEntity): List<String> {
return cityEntities
.filter { it.fruitAndVegetablesPrices.banana1kg != null }
.sortedBy { it.fruitAndVegetablesPrices.banana1kg }
.map { it.cityName }
.takeIf { it.isNotEmpty() } ?: listOf("No Valid Data is Entered !")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,31 @@ package interactor
import model.CityEntity

class GetCityHasCheapestInternetConnectionInteractor(
private val dataSource: CostOfLivingDataSource,
) {
private val dataSource: CostOfLivingDataSource, ) {

fun execute(): CityEntity{
throw Throwable("Not Implemented yet")
fun execute(limit: Int): String {
val list = dataSource
.getAllCitiesData()
.filter(::excludeNullAverageSalaryAndServicesPrices)
.sortingWithBestInternetPrice()
.take(limit)
.map { it.cityName }
return if (list.isEmpty())
""
else
list[0]
}

private fun excludeNullAverageSalaryAndServicesPrices(city: CityEntity): Boolean {
return city.averageMonthlyNetSalaryAfterTax != null && city.servicesPrices.internet60MbpsOrMoreUnlimitedDataCableAdsl != null
}


}
private fun List<CityEntity>.sortingWithBestInternetPrice(): List<CityEntity> {
return this.sortedByDescending {
(it.averageMonthlyNetSalaryAfterTax?.div(
it.servicesPrices.internet60MbpsOrMoreUnlimitedDataCableAdsl!!
))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package interactor

import model.CityEntity

class GetCityHasHighestRentingBetweenApartmentsInteractor(
private val dataSource: CostOfLivingDataSource
) {
fun execute(): CityEntity {
return dataSource
.getAllCitiesData()
.filter(::excludeNullValuesAndLowQualityData)
.sortingWithRentingPrices()
.take(1).first()
}

private fun excludeNullValuesAndLowQualityData(city: CityEntity): Boolean {
return city.realEstatesPrices.apartment3BedroomsInCityCentre != null
&& city.realEstatesPrices.apartment3BedroomsOutsideOfCentre != null
&& city.realEstatesPrices.apartmentOneBedroomInCityCentre != null
&& city.realEstatesPrices.apartmentOneBedroomOutsideOfCentre != null
&& city.dataQuality
}

private fun List<CityEntity>.sortingWithRentingPrices(): List<CityEntity> {
return this.sortedBy {
(it.realEstatesPrices.apartment3BedroomsInCityCentre
?.plus(it.realEstatesPrices.apartmentOneBedroomInCityCentre!!))
?.div(
it.realEstatesPrices.apartment3BedroomsOutsideOfCentre
?.plus(it.realEstatesPrices.apartmentOneBedroomOutsideOfCentre!!)!!
)
}
}

}
41 changes: 41 additions & 0 deletions src/main/kotlin/interactor/GetCityManagerExpectationInteractor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package interactor

import model.CityEntity

class GetCityManagerExpectationInteractor(
private val dataSource: CostOfLivingDataSource
) {
fun execute(): String? {
val data =
dataSource.getAllCitiesData()
.filter(::filterByCountry)
.sortingWithAveragePrice()

return if (data.isNotEmpty()) data[data.size / 2].cityName else null
}


private fun filterByCountry(city: CityEntity): Boolean {
return (city.country == "United States"
&& city.mealsPrices.mealAtMcDonaldSOrEquivalent != null
&& city.mealsPrices.mealInexpensiveRestaurant != null
&& city.mealsPrices.mealFor2PeopleMidRangeRestaurant != null
) || (city.country == "Canada"
&& city.mealsPrices.mealAtMcDonaldSOrEquivalent != null
&& city.mealsPrices.mealInexpensiveRestaurant != null
&& city.mealsPrices.mealFor2PeopleMidRangeRestaurant != null
) || (city.country == "Mexico"
&& city.mealsPrices.mealAtMcDonaldSOrEquivalent != null
&& city.mealsPrices.mealInexpensiveRestaurant != null
&& city.mealsPrices.mealFor2PeopleMidRangeRestaurant != null
)
}


private fun List<CityEntity>.sortingWithAveragePrice(): List<CityEntity> {
return this.sortedBy {
(it.mealsPrices.mealInexpensiveRestaurant?.plus(it.mealsPrices.mealAtMcDonaldSOrEquivalent!!)
?.plus(it.mealsPrices.mealFor2PeopleMidRangeRestaurant!!))?.div(3)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package interactor

import model.CityEntity
import java.lang.reflect.Executable

class GetCityNameAndSalrayAverageInteractor(private val dataSource: CostOfLivingDataSource) {


fun execute(country: String): List<Pair<String,Float>>
{
val list = dataSource
.getAllCitiesData()
.filter { (it.country == country.convert()) && (it.dataQuality) }.getSalary()
if(list.isEmpty())
{
throw Exception("Enter Valid Country")
}
return list
}
private fun List<CityEntity>.getSalary(): List<Pair<String, Float>> {
val newList = mutableListOf<Pair<String, Float>>()
var salary: Float
this.forEach{
salary =
it.averageMonthlyNetSalaryAfterTax!!
newList.add(Pair(it.cityName, salary))
}
return newList
}
private fun String.convert(): String {
return capitalize(lowercase())!!
}
private fun capitalize(str: String?): String? {
return str?.capitalize() ?: str
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package interactor

import model.CityEntity
import model.DrinksPrices


class GetHighestCarbonatedDrinksPricesInteractor(private val dataSource: CostOfLivingDataSource) {
fun execute(): Set<Pair<String, Float>> {

val city: List<CityEntity> = dataSource.getAllCitiesData()
.filter { nullAndLowQualityDrinks(it) }
.sortedByDescending { avgPriceForASingleCity(it) }

return if (city.isEmpty()) {
emptySet()
} else {
finalList(city)
}
}

private fun nullAndLowQualityDrinks(cityEntity: CityEntity): Boolean =

cityEntity.drinksPrices.cappuccinoRegularInRestaurants != null &&
cityEntity.drinksPrices.milkRegularOneLiter != null &&
cityEntity.drinksPrices.waterAThirdOfLiterBottleInRestaurants != null &&
cityEntity.drinksPrices.cokePepsiAThirdOfLiterBottleInRestaurants != null &&
cityEntity.drinksPrices.waterOneAndHalfLiterBottleAtTheMarket != null &&
cityEntity.dataQuality


// function to return the average prices for only one city
private fun avgPriceForASingleCity(cityEntity: CityEntity) = (cityEntity.drinksPrices.milkRegularOneLiter!! +
cityEntity.drinksPrices.cappuccinoRegularInRestaurants!! +
cityEntity.drinksPrices.waterOneAndHalfLiterBottleAtTheMarket!! +
cityEntity.drinksPrices.waterAThirdOfLiterBottleInRestaurants!! +
cityEntity.drinksPrices.cokePepsiAThirdOfLiterBottleInRestaurants!!) / 5

//a function to return the average prices for a whole country
private fun avgpriceforacountry(list: List<CityEntity>): Float {
val listofprices = mutableListOf<Float>()
var finalvalue = 0f
list.forEach {
listofprices.add(avgPriceForASingleCity(it))
}
listofprices.forEach {
finalvalue += it
}
return finalvalue / listofprices.size
}

// function to sort the list into a sorted set and return a list of 10 countries
fun finalList(list: List<CityEntity>) :Set<Pair<String,Float>> {
val finallist = mutableListOf<Pair<String, Float>>()
list.forEach { cityEntity ->
finallist .add(Pair(cityEntity.country,avgpriceforacountry(list.filter{cityEntity.country ==it.country })))

}
return finallist.toSet().take(10).toSet()
}
}
Loading