|
44 | 44 | "outputs": [], |
45 | 45 | "source": [ |
46 | 46 | "import grpc\n", |
47 | | - "from ni.datastore import TestResult\n", |
48 | | - "from ni.measurements.metadata.v1.metadata_store_pb2 import Operator, TestStation, SoftwareItem, ExtensionValue\n", |
| 47 | + "from ni.datastore import Operator, TestResult, TestStation, SoftwareItem\n", |
49 | 48 | "\n", |
50 | 49 | "# Invalid creation of operator - no badge_number provided\n", |
51 | 50 | "operator = Operator(operator_name=\"James Bowery\", schema_id=schema_id)\n", |
|
56 | 55 | " print(f\" {e.details()}\")\n", |
57 | 56 | "\n", |
58 | 57 | "# Add the required attribute to the operator object\n", |
59 | | - "operator.extensions[\"badge_number\"].CopyFrom(ExtensionValue(string_value=\"emp-128256\"))\n", |
| 58 | + "operator.extensions[\"badge_number\"] = \"emp-128256\"\n", |
60 | 59 | "operator_id = client.create_operator(operator)\n", |
61 | 60 | "\n", |
62 | 61 | "# Invalid creation of test station - location is invalid\n", |
63 | 62 | "test_station = TestStation(test_station_name=\"TestStation_12\", schema_id=schema_id)\n", |
64 | | - "test_station.extensions[\"location\"].CopyFrom(ExtensionValue(string_value=\"Texas\"))\n", |
| 63 | + "test_station.extensions[\"location\"] = \"Texas\"\n", |
65 | 64 | "try:\n", |
66 | 65 | " test_station_id = client.create_test_station(test_station)\n", |
67 | 66 | "except grpc.RpcError as e:\n", |
68 | 67 | " print(\"Failed to create test station:\")\n", |
69 | 68 | " print(f\" {e.details()}\")\n", |
70 | 69 | "\n", |
71 | 70 | "# Fix the location\n", |
72 | | - "test_station.extensions[\"location\"].CopyFrom(ExtensionValue(string_value=\"USA\"))\n", |
| 71 | + "test_station.extensions[\"location\"] = \"USA\"\n", |
73 | 72 | "test_station_id = client.create_test_station(test_station)\n", |
74 | 73 | "\n", |
75 | 74 | "# Invalid creation of software item - software license is invalid (not matching the pattern defined in the schema)\n", |
76 | 75 | "software_item = SoftwareItem(product=\"Windows\", version=\"10.0.19044\", schema_id=schema_id)\n", |
77 | | - "software_item.extensions[\"license\"].CopyFrom(ExtensionValue(string_value=\"enterprise_LIC\"))\n", |
| 76 | + "software_item.extensions[\"license\"] = \"enterprise_LIC\"\n", |
78 | 77 | "try:\n", |
79 | 78 | " software_item_id = client.create_software_item(software_item)\n", |
80 | 79 | "except grpc.RpcError as e:\n", |
81 | 80 | " print(\"Failed to create software item:\")\n", |
82 | 81 | " print(f\" {e.details()}\")\n", |
83 | 82 | "\n", |
84 | 83 | "# Fix the software license to create the software item\n", |
85 | | - "software_item.extensions[\"license\"].CopyFrom(ExtensionValue(string_value=\"LIC_enterprise\"))\n", |
| 84 | + "software_item.extensions[\"license\"] = \"LIC_enterprise\"\n", |
86 | 85 | "software_item_id = client.create_software_item(software_item)\n", |
87 | 86 | " \n", |
88 | 87 | "test_result = TestResult(\n", |
|
91 | 90 | " test_station_id=test_station_id,\n", |
92 | 91 | " schema_id=schema_id,\n", |
93 | 92 | " software_item_ids=[software_item_id])\n", |
94 | | - "test_result.extensions[\"session_file_path\"] = ExtensionValue(string_value=\"C:\\\\my_test_description.xlsx\")\n" |
| 93 | + "test_result.extensions[\"session_file_path\"] = \"C:\\\\my_test_description.xlsx\"\n" |
95 | 94 | ] |
96 | 95 | }, |
97 | 96 | { |
|
186 | 185 | " operator = client.get_operator(test_result.operator_id)\n", |
187 | 186 | " # badge_number is a custom attribute in the schema\n", |
188 | 187 | " # It's not a standard attribute of the operator object\n", |
189 | | - " badge_number = operator.extensions[\"badge_number\"].string_value\n", |
| 188 | + " badge_number = operator.extensions[\"badge_number\"]\n", |
190 | 189 | " print(f\"operator {operator.operator_name}'s badge number is: {badge_number}\")\n", |
191 | 190 | "\n", |
192 | 191 | " waveform = client.read_data(found_measurement, expected_type=AnalogWaveform)\n", |
|
0 commit comments