Diff
checker
Texte
Texte
Images
Documents
Excel
Dossiers
Legal
Enterprise
Application de bureau
Prix
Se connecter
Télécharger Diffchecker Desktop
Comparer le texte
Trouver la différence entre deux fichiers texte
Outils
Historique
Éditeur live
Masquer les espaces
Cacher identiques
Sans retour à la ligne
Vue
Divisé
Unifié
Niveau de précision
Intelligent
Mot
Caractère
Styles de texte
Modifier l’apparence
Coloration syntaxique
Choisir la syntaxe
Ignorer
Transformer le texte
Aller au premier écart
Modifier l'entrée
Diffchecker Desktop
La façon la plus sécurisée d'utiliser Diffchecker. Obtenez l'application Diffchecker Desktop : vos diffs ne quittent jamais votre ordinateur !
Obtenir Desktop
https://codereview.stackexchange.com/a/253314/30419
Créé
il y a 6 ans
Le diff n'expire jamais
Effacer
Exporter
Partager
Expliquer
55 suppressions
Lignes
Total
Supprimé
Caractères
Total
Supprimé
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
55 lignes
Copier tout
52 ajouts
Lignes
Total
Ajouté
Caractères
Total
Ajouté
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
55 lignes
Copier tout
Copier
Copié
Copier
Copié
#define
queueSize
16
let
queueSize
=
16
Copier
Copié
Copier
Copié
#define
increaseIndex(
x) ({x++; if(x >= queueSize) x = 0;})
func
increaseIndex(
_ x: Int) -> Int {
let x = x + 1
return x < queueSize
? x
: 0
}
Copier
Copié
Copier
Copié
int
rssiArray
[queueSize]
=
{0};
var
rssiArray
=
[0]
int
sortRssi
[queueSize]
=
{0};
var
sortRssi
=
[0]
int
rssiIndex = 0
;
var
rssiIndex = 0
Copier
Copié
Copier
Copié
static double
getDistance(
d
ouble
rssi, int
txPower
)
{
private func
getDistance(
rssi: D
ouble
,
txPower
: Int) -> Double?
{
if (
rssi == 0
) {
return
rssi == 0
return -1.0; // if we cannot determine accuracy, return -1.
? nil
}
:
pow(10, (
D
ouble
(
txPower
)
- rssi) /
20)
return
pow(10, (
(d
ouble
)
txPower
- rssi) /
(10 * 2));
}
}
Copier
Copié
Copier
Copié
static double calculateAccuracy(double rssi, int txPower) {
private func calculateAccuracy(rssi: Double, txPower: Int) -> Double? {
if (rssi == 0) {
guard rssi != 0 else {
return -1.0; // if we cannot determine accuracy, return -1.
return
nil
}
double ratio = rssi * 1.0 / txPower;
if (ratio < 1.0) {
return
pow(ratio, 10);
} else {
double accuracy = (0.89976) * pow(ratio, 7.7095) + 0.111;
return accuracy;
}
}
Copier
Copié
Copier
Copié
let ratio = rssi * (1 / Double(txPower))
return ratio < 1
? pow(ratio, 10)
: (0.89976) * pow(ratio, 7.7095) + 0.111
}
}
Copier
Copié
Copier
Copié
int cmp
func
(const void * a, const void * b)
{
private
func
calculateAverage() -> Double
{
return
( *(int*)a - *(int*)b );
sortRssi = Array(rssiArray.sorted(by: >).dropFirst(3))
return
sortRssi.averaged(while: { $0 != 0 })
}
}
Copier
Copié
Copier
Copié
static double calculateAverage()
{
double
average
= 0;
extension Collection where Element: BinaryInteger
{
int i = 0;
func
average
d(while allowedPrefixPredicate: (Element) -> Bool) -> Double {
int drop = 3;
lazy
memcpy(sort_rssi, rssi_array, queueSize * sizeof(int));
.prefix(while: allowedPrefixPredicate)
qsort(sort_rssi, queueSize, sizeof(int), cmpfunc);
.map(Double.init)
for (i = 0; i < queueSize - drop; ++i) {
.reduce(into: 0, +=)
if(sort_rssi[i + drop] == 0) break;
/ Double(count)
average += sort_rssi[i];
}
}
Copier
Copié
Copier
Copié
return average / i;
}
}
// For adding new rssi we can use this code:
// For adding new rssi we can use this code:
Copier
Copié
Copier
Copié
rssiArray[rssiIndex] = rssi
;
rssiArray[rssiIndex] = rssi
increaseIndex(rssiIndex)
;
rssiIndex =
increaseIndex(rssiIndex)
double
meanRssi = calculateAverage()
;
let
meanRssi = calculateAverage()
Différences enregistrées
Texte d'origine
Ouvrir un fichier
#define queueSize 16 #define increaseIndex(x) ({x++; if(x >= queueSize) x = 0;}) int rssiArray[queueSize] = {0}; int sortRssi[queueSize] = {0}; int rssiIndex = 0; static double getDistance(double rssi, int txPower) { if (rssi == 0) { return -1.0; // if we cannot determine accuracy, return -1. } return pow(10, ((double) txPower - rssi) / (10 * 2)); } static double calculateAccuracy(double rssi, int txPower) { if (rssi == 0) { return -1.0; // if we cannot determine accuracy, return -1. } double ratio = rssi * 1.0 / txPower; if (ratio < 1.0) { return pow(ratio, 10); } else { double accuracy = (0.89976) * pow(ratio, 7.7095) + 0.111; return accuracy; } } int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } static double calculateAverage() { double average = 0; int i = 0; int drop = 3; memcpy(sort_rssi, rssi_array, queueSize * sizeof(int)); qsort(sort_rssi, queueSize, sizeof(int), cmpfunc); for (i = 0; i < queueSize - drop; ++i) { if(sort_rssi[i + drop] == 0) break; average += sort_rssi[i]; } return average / i; } // For adding new rssi we can use this code: rssiArray[rssiIndex] = rssi; increaseIndex(rssiIndex); double meanRssi = calculateAverage();
Texte modifié
Ouvrir un fichier
let queueSize = 16 func increaseIndex(_ x: Int) -> Int { let x = x + 1 return x < queueSize ? x : 0 } var rssiArray = [0] var sortRssi = [0] var rssiIndex = 0 private func getDistance(rssi: Double, txPower: Int) -> Double? { return rssi == 0 ? nil : pow(10, (Double(txPower) - rssi) / 20) } private func calculateAccuracy(rssi: Double, txPower: Int) -> Double? { guard rssi != 0 else { return nil } let ratio = rssi * (1 / Double(txPower)) return ratio < 1 ? pow(ratio, 10) : (0.89976) * pow(ratio, 7.7095) + 0.111 } private func calculateAverage() -> Double { sortRssi = Array(rssiArray.sorted(by: >).dropFirst(3)) return sortRssi.averaged(while: { $0 != 0 }) } extension Collection where Element: BinaryInteger { func averaged(while allowedPrefixPredicate: (Element) -> Bool) -> Double { lazy .prefix(while: allowedPrefixPredicate) .map(Double.init) .reduce(into: 0, +=) / Double(count) } } // For adding new rssi we can use this code: rssiArray[rssiIndex] = rssi rssiIndex = increaseIndex(rssiIndex) let meanRssi = calculateAverage()
Trouver la différence