You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/01/09 06:10:43 UTC

[GitHub] [arrow] zixi-bwang commented on a change in pull request #12068: ARROW-15037: [C#] A stream processing example of IoT sensor data

zixi-bwang commented on a change in pull request #12068:
URL: https://github.com/apache/arrow/pull/12068#discussion_r780739266



##########
File path: csharp/examples/IoTDataPipelineExample/Model/SensorDataPipeline.cs
##########
@@ -0,0 +1,225 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+using Apache.Arrow;
+using Apache.Arrow.Ipc;
+using Apache.Arrow.Memory;
+using System.Threading.Channels;
+using System.Threading;
+using Apache.Arrow.Types;
+
+namespace IoTPipelineExample
+{
+    public class SensorDataPipeline
+    {
+        private int _size;
+        private readonly int _totalInputs;
+        private readonly int _queueCapacity;
+        private readonly Channel<SensorData> _channel;
+        ChannelWriter<SensorData> _writer;
+        ChannelReader<SensorData> _reader;
+
+        private readonly Dictionary<int, Int32Array.Builder> _colSubjectIdBuilderDict;
+        private readonly Dictionary<int, StringArray.Builder> _colActivityLabelBuilderDict;
+        private readonly Dictionary<int, TimestampArray.Builder> _colTimestampBuilderDict;
+        private readonly Dictionary<int, DoubleArray.Builder> _colXAxisBuilderDict;
+        private readonly Dictionary<int, DoubleArray.Builder> _colYAxisBuilderDict;
+        private readonly Dictionary<int, DoubleArray.Builder> _colZAxisBuilderDict;
+
+        public Dictionary<string, string> activityLabel = new Dictionary<string, string>()
+            {
+                {"walking", "A"},
+                {"jogging", "B"},
+                {"stairs", "C"},
+                {"sitting", "D"},
+                {"standing", "E"},
+                {"typing", "F"},
+                {"teeth", "G"},
+                {"soup", "H"},
+                {"chips", "I"},
+                {"pasta", "J"},
+                {"drinking", "K"},
+                {"sandwich", "L"},
+                {"kicking", "M"},
+                {"catch", "O"},
+                {"dribbling", "P"},
+                {"writing", "Q"},
+                {"clapping", "R"},
+                {"folding", "S"},
+            };
+
+        public SensorDataPipeline(int totalInputs, int queueCapacity)
+        {
+            _totalInputs = totalInputs;
+            _queueCapacity = queueCapacity;
+            _channel = Channel.CreateBounded<SensorData>(_queueCapacity);
+            _writer = _channel.Writer;
+            _reader = _channel.Reader;
+            _colSubjectIdBuilderDict = new Dictionary<int, Int32Array.Builder>();
+            _colActivityLabelBuilderDict = new Dictionary<int, StringArray.Builder>();
+            _colTimestampBuilderDict = new Dictionary<int, TimestampArray.Builder>();
+            _colXAxisBuilderDict = new Dictionary<int, DoubleArray.Builder>();
+            _colYAxisBuilderDict = new Dictionary<int, DoubleArray.Builder>();
+            _colZAxisBuilderDict = new Dictionary<int, DoubleArray.Builder>();
+        }
+
+        public async Task WriteToChannel(int taskNumber)
+        {
+            Random rand = new Random();
+            List<string> keyList = new List<string>(activityLabel.Keys);
+            int count = keyList.Count;
+            var basis = DateTimeOffset.UtcNow;
+
+            Console.WriteLine($"Write to channel task {taskNumber} started!");
+            while (await _writer.WaitToWriteAsync())
+            {
+                string randomKey = keyList[rand.Next(count)];
+                string label = activityLabel[randomKey];
+
+                // generate random missing values
+                if (rand.Next(10_000) == 9_999)
+                {
+                    label = null;
+                }
+
+                var item = new SensorData
+                {
+                    // approximately 9_000 unique subjects/sensors
+                    subjectId = rand.Next(1_001, 1_123),

Review comment:
       You are right.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org