chore: update sort direction and add comments
This commit is contained in:
parent
f78da37915
commit
b64b88883e
|
@ -109,7 +109,7 @@
|
||||||
<key>MastodonIntent.xcscheme_^#shared#^_</key>
|
<key>MastodonIntent.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>26</integer>
|
<integer>21</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>MastodonIntents.xcscheme_^#shared#^_</key>
|
<key>MastodonIntents.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
|
@ -124,12 +124,12 @@
|
||||||
<key>NotificationService.xcscheme_^#shared#^_</key>
|
<key>NotificationService.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>27</integer>
|
<integer>19</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>ShareActionExtension.xcscheme_^#shared#^_</key>
|
<key>ShareActionExtension.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>28</integer>
|
<integer>20</integer>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
<key>SuppressBuildableAutocreation</key>
|
<key>SuppressBuildableAutocreation</key>
|
||||||
|
|
|
@ -115,8 +115,11 @@ extension MastodonPickServerViewModel {
|
||||||
if self.mode == .signUp {
|
if self.mode == .signUp {
|
||||||
indexedServers = indexedServers.filter { !$0.approvalRequired }
|
indexedServers = indexedServers.filter { !$0.approvalRequired }
|
||||||
}
|
}
|
||||||
|
// Note:
|
||||||
|
// sort by calculate last week users count
|
||||||
|
// and make medium size (~800) server to top
|
||||||
|
|
||||||
// group by language user preferred language first. Then sort by `totalUsers`
|
// group by language user preferred language first
|
||||||
var languageToServersMapping = OrderedDictionary<String, [Mastodon.Entity.Server]>()
|
var languageToServersMapping = OrderedDictionary<String, [Mastodon.Entity.Server]>()
|
||||||
for language in Locale.preferredLanguages {
|
for language in Locale.preferredLanguages {
|
||||||
let local = Locale(identifier: language)
|
let local = Locale(identifier: language)
|
||||||
|
@ -129,10 +132,10 @@ extension MastodonPickServerViewModel {
|
||||||
.sorted(by: { lh, rh in
|
.sorted(by: { lh, rh in
|
||||||
let lhValue = abs(log2(800.0) - log2(Double(lh.lastWeekUsers)))
|
let lhValue = abs(log2(800.0) - log2(Double(lh.lastWeekUsers)))
|
||||||
let rhValue = abs(log2(800.0) - log2(Double(rh.lastWeekUsers)))
|
let rhValue = abs(log2(800.0) - log2(Double(rh.lastWeekUsers)))
|
||||||
return lhValue > rhValue
|
return lhValue < rhValue
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// sort remains servers by `totalUsers`
|
// sort remains servers
|
||||||
let remainsServers = indexedServers
|
let remainsServers = indexedServers
|
||||||
.filter { server in
|
.filter { server in
|
||||||
return !languageToServersMapping.contains { _, servers in servers.contains(server) }
|
return !languageToServersMapping.contains { _, servers in servers.contains(server) }
|
||||||
|
@ -140,7 +143,7 @@ extension MastodonPickServerViewModel {
|
||||||
.sorted(by: { lh, rh in
|
.sorted(by: { lh, rh in
|
||||||
let lhValue = abs(log2(800.0) - log2(Double(lh.lastWeekUsers)))
|
let lhValue = abs(log2(800.0) - log2(Double(lh.lastWeekUsers)))
|
||||||
let rhValue = abs(log2(800.0) - log2(Double(rh.lastWeekUsers)))
|
let rhValue = abs(log2(800.0) - log2(Double(rh.lastWeekUsers)))
|
||||||
return lhValue > rhValue
|
return lhValue < rhValue
|
||||||
})
|
})
|
||||||
|
|
||||||
var _indexedServers: [Mastodon.Entity.Server] = []
|
var _indexedServers: [Mastodon.Entity.Server] = []
|
||||||
|
|
Loading…
Reference in New Issue