How to generate fake data on Image Marker

Hi. I am currently trying to make an indoor locating system. Using Image Marker, I managed to upload an indoor floor layout/map. How can I generate fake data to make my devices appear to be in motion on the map?

Hello, @thadam.pm

To generate fake data on your layer with the impression that the pins are moving. What you have to do is run an analysis every 5 minutes for example, looking for the current pin coordinates and updating as you wish. Here’s an example of analysis for this. Just adapt it to perform the movement you want. After adapting it to use this analysis in your application, simply choose a time interval to run this analysis.

Note: To use this analysis, you need to have the pins already placed in your layer. If you do not have, place the pins before running the analysis.

Tip: To make it easier to know which coordinates to use on your pins and to trace the movement you want, enable the “Show x, y coordinates” option available on the “Visualization” tab.

Analysis example

// Requiring some constants
const Analysis = require('tago/analysis');
const Device = require('tago/device');

async function myAnalysis(context) {
  // Configurating device, services and account objects
  const device = new Device('YOUR DEVICE TOKEN HERE');

  // Getting the variable you are using as a pin
  let [variableYouWant] = await device.find({
    variable: 'variableYouWant',
    query: 'last_item',
    qty: 1,
  });

  // Initially, your variable will not have metadata, so I treated this case here
  if (!variableYouWant.metadata) {
    variableYouWant.metadata = {}
    variableYouWant.metadata.x = 0.25;
    variableYouWant.metadata.y = 0.40;
  }

  // Checking the current coordinates to decide what coordinates I will insert
  if (variableYouWant.metadata.x === 0.25) {
    // The coordinates are stored in metadata.y and metadata.x
    variableYouWant.metadata.x = 0.75;
    variableYouWant.metadata.y = 0.40;
  } else if (variableYouWant.metadata.x === 0.75) {
    variableYouWant.metadata.x = 0.25;
    variableYouWant.metadata.y = 0.40;
  }

  // Inserting the variable with new coordinates
  await device.insert(variableYouWant);
}

module.exports = new Analysis(myAnalysis, 'YOUR ANALYSIS TOKEN HERE');

I hope this can help you, let me know if you have any questions about it.

Thanks!

1 Like

Thank you Kelvin. :+1:

1 Like