Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ Lite file does not have the last three, so each of them reads
The IP Intelligence example looks up `116.154.188.222`, `45.236.48.61` and an
IPv6 address. For each it prints `Input values:` with `query.client-ip`, then
`Results:` with a line for each property, from `RegisteredName` to
`TimeZoneOffset`. The Lite file has RegisteredName, RegisteredOwner and
RegisteredCountry, so every other line reads `needs the Enterprise data file`.
`TimeZoneOffset`. Each value is followed by its weighting, as in
`Japan (weighting 1.00)`. The Lite file has RegisteredName, RegisteredOwner
and RegisteredCountry, so every other line reads `needs the Enterprise data
file`.

Both then end the same way, where `<tier>` is `Lite` for Device Detection and
`IPIV4Lite` for IP Intelligence.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -60,6 +61,8 @@ public class PropertyHelper {
* List&lt;IWeightedValue&lt;T&gt;&gt; even when the declared type is T).
* For single-element lists, returns just the value.
* For multi-element lists, returns values joined with ", ".
* A weighted value is followed by its weighting, as in
* "Japan (weighting 1.00)".
* @param value the raw value from AspectPropertyValue.getValue()
* @return the unwrapped string representation
*/
Expand All @@ -73,8 +76,16 @@ private static String unwrapValue(Object value) {
return list.stream()
.map(item -> {
if (item instanceof IWeightedValue) {
Object inner = ((IWeightedValue<?>) item).getValue();
return inner != null ? inner.toString() : "Unknown";
// An IP Intelligence value comes with the
// weighting the data gives it, which is 1 for
// a property with one answer.
IWeightedValue<?> weighted = (IWeightedValue<?>) item;
Object inner = weighted.getValue();
return String.format(
Locale.ROOT,
"%s (weighting %.2f)",
inner != null ? inner.toString() : "Unknown",
weighted.getWeighting());
}
return item != null ? item.toString() : "Unknown";
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@

package fiftyone.ipintelligence.examples.shared;

import fiftyone.pipeline.core.data.IWeightedValue;
import fiftyone.pipeline.core.data.WeightedValue;
import fiftyone.pipeline.engines.data.AspectPropertyValue;
import fiftyone.pipeline.engines.data.AspectPropertyValueDefault;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -60,4 +64,25 @@ public void testAsNoValue() {
AspectPropertyValue<List<Boolean>> test = new AspectPropertyValueDefault<>();
assertTrue(PropertyHelper.asString(test).startsWith("Unknown"));
}

/**
* Each weighted value is shown with its weighting, as the IP
* Intelligence examples must show both. A raw weighting of 65535 is a
* weighting of 1.
*/
@Test
public void testWeightedValuesShowTheirWeighting() {
AspectPropertyValue<List<IWeightedValue<String>>> one =
new AspectPropertyValueDefault<>(Collections.singletonList(
new WeightedValue<>(65535, "Japan")));
assertEquals("Japan (weighting 1.00)", PropertyHelper.asString(one));

AspectPropertyValue<List<IWeightedValue<String>>> two =
new AspectPropertyValueDefault<>(Arrays.asList(
new WeightedValue<>(49151, "Tokyo"),
new WeightedValue<>(16384, "Osaka")));
assertEquals(
"Tokyo (weighting 0.75), Osaka (weighting 0.25)",
PropertyHelper.asString(two));
}
}
Loading