MLopezJ / LWM2M-JSONSchema

LWM2M protocol From XML to JSON Schema
0 stars 0 forks source link

Total amount of multiple instances and single instances #10

Closed MLopezJ closed 1 year ago

MLopezJ commented 1 year ago

In order to take the decision about how to implement multiple and single instances in the typebox LwM2M object definition is required to know how many multiple and instances are in the protocol.

MLopezJ commented 1 year ago

Single instances: 87

Multiple instances: 215

MLopezJ commented 1 year ago

lwm2m-registry folder is composed of 309 items, 1 of them is the readme and the other is a version history folder, so those 2 are discarded; there is 307 files in total.

Then, 5 of them ("Common", "DDF", "LWM2M_senml_units", "LWM2M-v1_1", "LWM2M") are discarded as well because are like metadata related to the protocol but not a proper registry, so there are 302 items to check.

215 multiple instances +87 single instances = 302 items.

MLopezJ commented 1 year ago

list of single instance registries:

[
  10, 10244, 10245, 10246, 10248, 10250, 10252, 10253, 10255, 10265, 10286,
  10299, 10315, 10316, 10318, 10319, 10326, 10329, 10330, 10331, 10333, 10336,
  10338, 10339, 10341, 10342, 10347, 10349, 10352, 10353, 10355, 10356, 10357,
  10363, 10364, 10365, 10369, 10371, 13, 20, 2049, 28, 3, 3351, 3353, 3354,
  3355, 3356, 3357, 3358, 3359, 3360, 3361, 3362, 3363, 3364, 3365, 3366, 3367,
  3368, 3369, 3370, 3372, 3373, 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381,
  3382, 3383, 3384, 3385, 3386, 3410, 3415, 3430, 3436, 4, 5, 508, 6, 7, 8,
]

list of multiple instance registries:

[
  0, 1, 10241, 10242, 10243, 10247, 10249, 10251, 10254, 10256, 10257, 10258,
  10259, 10260, 10262, 10263, 10264, 10266, 10267, 10268, 10269, 10270, 10271,
  10272, 10273, 10274, 10275, 10276, 10277, 10278, 10279, 10280, 10281, 10282,
  10283, 10284, 10290, 10291, 10292, 10300, 10308, 10309, 10311, 10313, 10314,
  10320, 10322, 10323, 10324, 10327, 10328, 10332, 10334, 10335, 10337, 10340,
  10343, 10344, 10345, 10346, 10348, 10350, 10351, 10354, 10358, 10359, 10360,
  10361, 10362, 10366, 10368, 10374, 10375, 10376, 10377, 10378, 11, 12, 14, 15,
  16, 18830, 18831, 19, 2, 2048, 2050, 2051, 2052, 2053, 2054, 2055, 2056, 2057,
  21, 22, 23, 24, 25, 26, 27, 3200, 3201, 3202, 3203, 3300, 3301, 3302, 3303,
  3304, 3305, 3306, 3308, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318,
  3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3329, 3330, 3331,
  3332, 3333, 3334, 3335, 3336, 3337, 3338, 3339, 3340, 3341, 3342, 3343, 3344,
  3345, 3346, 3347, 3348, 3349, 3350, 3352, 3371, 3387, 3388, 3389, 3390, 3391,
  3392, 3393, 3394, 3395, 3396, 3397, 3398, 3399, 3400, 3401, 3402, 3403, 3404,
  3405, 3406, 3407, 3408, 3411, 3412, 3413, 3414, 3416, 3417, 3418, 3419, 3420,
  3421, 3423, 3424, 3425, 3426, 3427, 3428, 3429, 3431, 3432, 3433, 3434, 3435,
  3437, 3438, 3439, 3441, 3442, 500, 501, 502, 503, 504, 505, 507, 509, 510, 9,
]
MLopezJ commented 1 year ago

Script used to get the data


//About: get how many of the objects are multiple instance and how many are single instance

import path from "path";
import fs from "fs";
import { readFile, writeFile } from "fs/promises";

const EXTENSION = ".json";
const dirpath = path.join("./lwm2m-registry-json");

const multipleInstance: { multiple: boolean; object: string }[] = [];
const singleInstance: { multiple: boolean; object: string }[] = [];

/**
 * Check if registry is defined as multiple or single instance
 * @param Lwm2mRegistry
 * @returns { multiple: boolean; object: string }[]
 */
const getInfo = (Lwm2mRegistry: any): { multiple: boolean; object: string } => {
  const id: string = Lwm2mRegistry.ObjectID[0];

  const isMultiple =
    Lwm2mRegistry.MultipleInstances[0] === "Single" ? false : true;

  return { multiple: isMultiple, object: id };
};

/**
 * Read file
 * @param element
 */
const readJson = async (element: any) => {
  const fileName = element.split(".")[0];
  if (
    !["Common", "DDF", "LWM2M_senml_units", "LWM2M-v1_1", "LWM2M"].includes(
      fileName
    )
  ) {
    console.log(`-- processing element ${fileName} --`);
    const jsonPath = `./lwm2m-registry-json/${fileName}.json`;
    const json = JSON.parse(await readFile(jsonPath, "utf-8"));
    const instanceType = getInfo(json.LWM2M.Object[0]);
    instanceType.multiple
      ? multipleInstance.push(instanceType)
      : singleInstance.push(instanceType);
  }
};

fs.readdir(dirpath, async (err, files) => {
  for (const file of files) {
    if (path.extname(file) === EXTENSION) {
      await readJson(file);
    }
  }
  const multiple = multipleInstance.map((element) => element.object);
  await writeFile("./multipleInstance.ts", `const multiple = [${multiple}]`);
  const single = singleInstance.map((element) => element.object);
  await writeFile("./single.ts", `const single = [${single}]`);
});