<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tal Kleiner on Medium]]></title>
        <description><![CDATA[Stories by Tal Kleiner on Medium]]></description>
        <link>https://medium.com/@talkleiner?source=rss-9d85f9ed516d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QTq7oD2tuUIaMlr5</url>
            <title>Stories by Tal Kleiner on Medium</title>
            <link>https://medium.com/@talkleiner?source=rss-9d85f9ed516d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 03:26:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@talkleiner/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Suzuki Service Manuals — how to get them programatically]]></title>
            <link>https://medium.com/@talkleiner/suzuki-service-manuals-how-to-get-them-programatically-2f4c3353e988?source=rss-9d85f9ed516d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f4c3353e988</guid>
            <category><![CDATA[suzuki-jimny]]></category>
            <category><![CDATA[headless-chrome]]></category>
            <category><![CDATA[suzuki]]></category>
            <category><![CDATA[service-manuals]]></category>
            <dc:creator><![CDATA[Tal Kleiner]]></dc:creator>
            <pubDate>Tue, 10 Mar 2026 19:42:52 GMT</pubDate>
            <atom:updated>2026-03-10T19:42:52.026Z</atom:updated>
            <content:encoded><![CDATA[<p>I just wrote and used a headless Chrome script (with the help of Claude Opus 4.6) to fetch the service manual for a specific Suzuki VIN and save all PDFs into a navigational structure of files.</p><p>There are several steps required for this to work, and it involves paying a fee for digital access to the service manual.</p><p>First, you need to register on the Suzuki EU portal:<br><a href="https://serviceportal.suzuki.eu/isoportal/">https://serviceportal.suzuki.eu/isoportal/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Td38gv2wwBl3oQ1oJWzz1w.png" /><figcaption>service portal</figcaption></figure><p>Two years ago, Israel was not available as a country option, so I created an Austrian address and VAT (Value Added Tax ID number). Basically, you need to register a business with a local VAT number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zXsJGotFRrqtqjfNLDwUFQ.png" /><figcaption>registering a business</figcaption></figure><p>After that, log in to the portal and pay for a new contract.</p><p>There are options for 1 hour, 1 day, 1 week, 1 month, or 1 year of digital access to Suzuki’s service manuals.</p><p>You decide how much time it will take you to set up and run the script to download your specific car’s VIN manual. I chose 1 week for 40 euros.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RFq3oT5os3QU4yuT7Z27Xw.png" /><figcaption>pricing</figcaption></figure><p>Next, search for your car’s VIN under: “Vehicle identification through use of VIN”.</p><p>This is the number embedded on your car’s frame and is unique to the specific vehicle you own. In my Suzuki Jimny, it is on the top left side of the engine bay.</p><p>You can also find it on your car’s license.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZWtPRxxl7yCTuTShmN0acQ.png" /><figcaption>searching for vin</figcaption></figure><p>After you find the VIN and the associated vehicle model, search for a link called:</p><p>XXXXX SERVICE MANUAL</p><p>where XXXXX is your vehicle type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*clDcH51gdZf4mHZrD1wEAg.png" /><figcaption>documents</figcaption></figure><p>This will take you to the service manual URL for your vehicle.</p><p>For example, mine for the 2016 Suzuki Jimny is:<br><a href="https://serviceportal.suzuki.eu/isoportal/files/manuals/SVG/AENER70A/index.html">https://serviceportal.suzuki.eu/isoportal/files/manuals/SVG/AENER70A/index.html</a></p><p>It is an interactive webpage (legacy XSLTProcessor).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vjz1d6nVpEs5ySDcPsut5w.png" /><figcaption>service manual interactive webpage</figcaption></figure><p>This URL should be given to the headless Chrome script.</p><p>You should also provide the script with the username and password so it can log in. Put them in the .env file.</p><p>The script will then expand all navigation links and start saving the results as PDFs into the same structure on your local file system.</p><p>Two years ago I couldn’t imagine finding two hours of free time to do this project. Human evolution is a marvelous thing.</p><p>Here is the repository with the code and instructions on how to run it: <a href="https://github.com/talkl/suzuki-service-manuals">https://github.com/talkl/suzuki-service-manuals</a></p><p>You can find me on LinkedIn if you have any questions:<br><a href="https://www.linkedin.com/in/smallest/">https://www.linkedin.com/in/smallest/</a></p><p>Cheers,</p><p>Tal</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f4c3353e988" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VS Code Extension: JetBrains Move Caret to Code Block Keybinding]]></title>
            <link>https://medium.com/@talkleiner/vs-code-extension-jetbrains-move-caret-to-code-block-keybinding-8629b70d2035?source=rss-9d85f9ed516d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8629b70d2035</guid>
            <category><![CDATA[webstorm]]></category>
            <category><![CDATA[cursor]]></category>
            <category><![CDATA[keymap]]></category>
            <category><![CDATA[ide]]></category>
            <category><![CDATA[jetbrains]]></category>
            <dc:creator><![CDATA[Tal Kleiner]]></dc:creator>
            <pubDate>Wed, 02 Apr 2025 06:29:34 GMT</pubDate>
            <atom:updated>2025-04-02T06:30:39.122Z</atom:updated>
            <content:encoded><![CDATA[<p>Working in the Node.js ecosystem — like many at my organization — I wanted to move to the Cursor IDE (a VS Code fork). However, I kept another window open for my favorite IDE, JetBrains WebStorm, mainly for its Git capabilities and excellent navigation.</p><p>Throughout this transition, I realized that I was missing three significant features:</p><p><strong>Navigation by Symbol<br></strong>In JetBrains IDEs, if I hold Cmd (on macOS) or Ctrl (on Windows) and click (left mouse button) on a symbol, I see a single-level list of occurrences. If I click the occurrence in that list, I’m immediately taken to the relevant code. However, in VS Code, this experience is more cumbersome: I’m shown a collapsed list of occurrences. I first need to expand the search results for each file to view the relevant preview, then click again to reach the code, which slows me down considerably.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rRr8kVmv5-KUc-dw3dIYzA.gif" /><figcaption>Jetbrains</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bqDt_PdZucyr0hgZZ6CX-A.gif" /><figcaption>VS Code</figcaption></figure><p><strong>Git Capabilities</strong><br>I really like how merge conflicts are displayed for easy resolution, and how quickly I can check out to another branch from the current one in JetBrains IDEs. There’s also the “Git ToolBox” plugin, which automatically fetches, displays inline blame, cleans up branches, and has a recent-branches switcher. I haven’t found anything quite as elegant in the VS Code Extensions Marketplace yet — feel free to drop any recommendations in the comments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*07hdiEB_dexCdaqAuU0eHw.png" /><figcaption>Git ToolBox</figcaption></figure><p><strong>Move Caret to Code Block Start/End Keybinding<br></strong>This happens to me a lot in test files — I want to visually and conceptually gather pieces of code to understand where they start and end. In JetBrains IDEs, the Move Caret to Code Block keybinding allows me to jump to the start of a code block (Cmd+Alt+[ on macOS) or the end of it (Cmd+Alt+]). Repeatedly pressing these shortcuts lets me move further outward, eventually reaching the top-level code block. This feature is incredibly helpful: if I’m inside a test file with multiple “describe” blocks, I often need to jump to the “beforeAll” of the current block to see which entities are being prepared, then jump up to the top-level “describe” to see which entities are being saved, and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jxtV0IGIEV-vKsxKWbVDMQ.gif" /></figure><p>I haven’t found a way to solve items #1 and #2 yet. For item #3, I tried the IntelliJ IDEA Keybindings extension, hoping it would address the problem, but unfortunately, it doesn’t support this particular keybinding. They state it’s because a specific protocol is needed to detect code blocks for every language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QgG4gIxxuxVhbVMJbsPtuA.png" /><figcaption>No support</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QVXhGpSoVrPj3xZzYRZALw.png" /><figcaption>A protocol is required</figcaption></figure><p>So, I ended up writing my own extension to add a Move Caret to Code Block keybinding. You can find it here: <a href="https://marketplace.visualstudio.com/items?itemName=TalKleiner.jetbrains-move-caret-to-code-block-keybinding">JetBrains Move Caret to Code Block Keybinding</a></p><p>It does have a limitation: I’ve only tested it with JavaScript and TypeScript so far. This is because you have to ignore curly braces that are part of comments and strings in JavaScript; other languages may have different syntax, meaning additional logic and tests would be required.</p><p>Example of ignoring curly braces in various contexts:</p><pre>// This is a comment with {curly braces} that should be ignored<br>/* This is a comment with {curly braces} that should be ignored */<br>const str1 = &#39;String with {curly braces} that should be ignored&#39;;<br>const str2 = &quot;String with {curly braces} that should be ignored&quot;;<br>const str3 = \`String with {curly braces} that should be ignored\`;</pre><p>Feel free to submit a pull request if you’d like to support other languages. <a href="https://github.com/talkl/jetbrains-move-caret-to-code-block-keybinding">GitHub Repository</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*tigIwRBwgoU5qt_W0-piiQ.gif" /><figcaption>JetBrains Move Caret to Code Block Keybinding Demo</figcaption></figure><p>I’d love to hear other migration stories from JetBrains to Cursor. Thanks for reading and see you around!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8629b70d2035" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Proved Through Statistics That My Suzuki Jimny Was Cured of Overheating]]></title>
            <link>https://medium.com/@talkleiner/how-i-proved-through-statistics-that-my-suzuki-jimny-was-cured-of-overheating-7ab4e2e19112?source=rss-9d85f9ed516d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ab4e2e19112</guid>
            <category><![CDATA[jimny]]></category>
            <category><![CDATA[hypothesis-testing]]></category>
            <category><![CDATA[overheating-problem]]></category>
            <dc:creator><![CDATA[Tal Kleiner]]></dc:creator>
            <pubDate>Fri, 05 Jul 2024 08:49:23 GMT</pubDate>
            <atom:updated>2024-07-05T08:59:49.404Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VPXB1Nq9iw_ZZSDW9jpSAw.jpeg" /><figcaption>Har Tzin — Negev’s center</figcaption></figure><p>I’ve owned my automatic 2016 Suzuki Jimny since August 2022. It has been a terrific ride exploring the wilderness of Israel, especially the desolate sand and mountains of the Negev. Recently though, I noticed that on steep slopes where the Jimny needs to push through with more force, the coolant gauge was signaling overheating. I immediately stopped the car and waited for the engine coolant to cool down. After it had, I returned down the mountain and the temperature gauge remained steadily in the middle. The same thing happened once more, so I knew I needed to find the reason for the overheating and fix it.</p><p>The problem wasn’t obvious because the coolant temperature was only heating up at those specific slopes and under that specific workload. On other occasions, like cruising down the highway, there was no indication of overheating, not even in traffic jams. It seemed that the problem was only occurring at low speeds when the engine worked harder off-road.</p><p>I took the car to a famous Jimny mechanic in the center of Israel. He didn’t manage to diagnose the problem properly and tried blindly to change the radiator’s cap and fill the overflow tank with Suzuki’s original engine coolant. I knew right there and then that the problem would return. And indeed it did. Same slope — the Jimny was overheating.</p><p>I conceived a plan that led to this article: What if I could measure the car’s computer sensors through an OBD and use my coding skills and some statistics to figure out if a specific fix had resolved the overheating problem?</p><h4>Extracting the data</h4><p>To get the data from the car to the cloud, I bought a highly-rated <a href="https://www.aliexpress.com/item/1005003228146739.html">OBD scanner</a> from Aliexpress that had a Bluetooth connection option. From the phone, the way to the cloud was fairly quick.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l-pOBaciGC7V4AxCBI4sqA.png" /><figcaption>OBD scanner</figcaption></figure><p>A friend recommended the <a href="https://play.google.com/store/apps/details?id=org.prowl.torque">Torque Pro</a> app for my Android phone. This app had an important feature to upload the sensor data at specific intervals to a web server. The idea was to open a web server to capture the data and save it in the cloud in a database of my choice. For iPhone users, I would recommend searching for an OBD app with a similar feature of sending data to a custom URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*gCvF8KNXfxJvowanDEOyxA.jpeg" /><figcaption>OBD App that can send the data to a webserver url</figcaption></figure><p>I wanted this project to be as cost-effective as possible, so I chose the following solutions:</p><p>1. <strong>Webserver</strong> — <a href="https://aws.amazon.com/pm/lambda">AWS Lambda</a><br>Lambda has a free tier of 1 million invocations before you start paying. I knew I would send data every 5 seconds, so this wasn’t an issue.</p><p>2. <strong>Database</strong> — <a href="https://www.influxdata.com/">InfluxDB</a><br>InfluxDB is the most popular open-source database for managing time series data. It offers 30 days of free storage, which was sufficient for my needs.</p><p>3. <strong>Public endpoint + Authentication</strong> — <a href="https://docs.aws.amazon.com/apigateway/">AWS API Gateway</a><br>Like Lambda, it has a generous free tier. I used it to expose a public endpoint with drag-and-drop style authentication setup and integrated this endpoint with my Lambda.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HdnGGoLCUXcOX0BRCUiJTw.png" /><figcaption>Amazon Web Services cost explorer</figcaption></figure><p>This setup turned out to be great; it only cost me $0.02 for 16,000 invocations, which I would call a success. Here is a summary of the architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hnI7C0YoT-xDn32aUC-8vw.png" /><figcaption>Data flow architecture</figcaption></figure><h4>Lambda code</h4><p>The API gateway endpoint was configured to invoke a specific Lambda function for authentication. I used a constant password, nothing too fancy, as I just wanted to prohibit unauthorized access.</p><p>Here’s the Lambda code to save the data points:</p><pre>import { InfluxDBClient, Point } from &#39;@influxdata/influxdb3-client&#39;;<br><br>const host = process.env.INFLUX_HOST;<br>const token = process.env.INFLUX_TOKEN;<br>const database = process.env.INFLUX_DATABASE;<br>const measurement = &#39;jimny&#39;;<br><br>const PID_DICT = {<br>    &quot;k10&quot;: &quot;maf&quot;,<br>    &quot;k11&quot;: &quot;throttlepos&quot;,<br>    &quot;k12&quot;: &quot;airstatus&quot;,<br>    &quot;k14&quot;: &quot;fueltrimb1s1&quot;,<br>    &quot;k15&quot;: &quot;fueltrimb1s2&quot;,<br>    &quot;k16&quot;: &quot;fuelstrimb1s3&quot;,<br>    &quot;k17&quot;: &quot;fuelstrimb1s4&quot;,<br>    &quot;k18&quot;: &quot;fuelstrimb2s1&quot;,<br>    &quot;k19&quot;: &quot;fuelstrimb2s2&quot;,<br>    &quot;k1a&quot;: &quot;fuelstrimb2s3&quot;,<br>    &quot;k1b&quot;: &quot;fuelstrimb2s4&quot;,<br>    &quot;k1f&quot;: &quot;enginestartedsince&quot;,<br>    &quot;k21&quot;: &quot;distancetraveledmil&quot;,<br>    &quot;k22&quot;: &quot;fuelrailpressurerel&quot;,<br>    &quot;k23&quot;: &quot;fuelrailpressure&quot;,<br>    &quot;k24&quot;: &quot;o2sensor1eqratio&quot;,<br>    &quot;k25&quot;: &quot;o2sensor2eqratio&quot;,<br>    &quot;k26&quot;: &quot;o2sensor3eqratio&quot;,<br>    &quot;k27&quot;: &quot;o2sensor4eqratio&quot;,<br>    &quot;k28&quot;: &quot;o2sensor5eqratio&quot;,<br>    &quot;k29&quot;: &quot;o2sensor6eqratio&quot;,<br>    &quot;k2a&quot;: &quot;o2sensor7eqratio&quot;,<br>    &quot;k2b&quot;: &quot;o2sensor8eqratio&quot;,<br>    &quot;k2c&quot;: &quot;egrcmd&quot;,<br>    &quot;k2d&quot;: &quot;egrerr&quot;,<br>    &quot;k2f&quot;: &quot;fuellevelecu&quot;,<br>    &quot;k3&quot;: &quot;fuelstatus&quot;,<br>    &quot;k31&quot;: &quot;distancesinceclearcodes&quot;,<br>    &quot;k32&quot;: &quot;evappressure&quot;,<br>    &quot;k33&quot;: &quot;baropressure&quot;,<br>    &quot;k34&quot;: &quot;o2sensor1eqratioalt&quot;,<br>    &quot;k3c&quot;: &quot;Catalyst Temperature (Bank 1 Sensor 1)&quot;,<br>    &quot;k3d&quot;: &quot;Catalyst Temperature (Bank 2 Sensor 1)&quot;,<br>    &quot;k3e&quot;: &quot;Catalyst Temperature (Bank 1 Sensor 2)&quot;,<br>    &quot;k3f&quot;: &quot;Catalyst Temperature (Bank 2 Sensor 2)&quot;,<br>    &quot;k4&quot;: &quot;Engine Load&quot;,<br>    &quot;k42&quot;: &quot;batteryvoltage&quot;,<br>    &quot;k43&quot;: &quot;engineload&quot;,<br>    &quot;k44&quot;: &quot;Commanded Equivalence Ratio(lambda)&quot;,<br>    &quot;k45&quot;: &quot;throttlepositionrel&quot;,<br>    &quot;k46&quot;: &quot;airtempambient&quot;,<br>    &quot;k47&quot;: &quot;throttlepositionabs&quot;,<br>    &quot;k49&quot;: &quot;Accelerator PedalPosition D&quot;,<br>    &quot;k4a&quot;: &quot;Accelerator PedalPosition E&quot;,<br>    &quot;k4b&quot;: &quot;Accelerator PedalPosition F&quot;,<br>    &quot;k5&quot;: &quot;coolanttemp&quot;,<br>    &quot;k52&quot;: &quot;Ethanol Fuel %&quot;,<br>    &quot;k5a&quot;: &quot;acceleratorpedalposrel&quot;,<br>    &quot;k5c&quot;: &quot;oiltemp&quot;,<br>    &quot;k6&quot;: &quot;Fuel Trim Bank 1 Short Term&quot;,<br>    &quot;k7&quot;: &quot;Fuel Trim Bank 1 Long Term&quot;,<br>    &quot;k78&quot;: &quot;Exhaust Gas Temperature 1&quot;,<br>    &quot;k79&quot;: &quot;Exhaust Gas Temperature 2&quot;,<br>    &quot;k8&quot;: &quot;Fuel Trim Bank 2 Short Term&quot;,<br>    &quot;k9&quot;: &quot;Fuel Trim Bank 2 Long Term&quot;,<br>    &quot;ka&quot;: &quot;Fuel pressure&quot;,<br>    &quot;kb&quot;: &quot;Intake Manifold Pressure&quot;,<br>    &quot;kb4&quot;: &quot;Transmission Temperature(Method 2)&quot;,<br>    &quot;kc&quot;: &quot;rpm&quot;,<br>    &quot;kd&quot;: &quot;speedobd&quot;,<br>    &quot;ke&quot;: &quot;Timing Advance&quot;,<br>    &quot;kf&quot;: &quot;airtemperatureintake&quot;,<br>    &quot;kfe1805&quot;: &quot;Transmission Temperature(Method 1)&quot;,<br>    &quot;kff1001&quot;: &quot;speedgps&quot;,<br>    &quot;kff1005&quot;: &quot;gpslon&quot;,<br>    &quot;kff1006&quot;: &quot;gpslat&quot;,<br>    &quot;kff1007&quot;: &quot;gpsbearing&quot;,<br>    &quot;kff1010&quot;: &quot;gpsalt&quot;,<br>    &quot;kff1201&quot;: &quot;mpg&quot;,<br>    &quot;kff1202&quot;: &quot;Turbo Boost &amp; Vacuum Gauge&quot;,<br>    &quot;kff1203&quot;: &quot;kpl&quot;,<br>    &quot;kff1204&quot;: &quot;tripdistance&quot;,<br>    &quot;kff1205&quot;: &quot;tripmpg&quot;,<br>    &quot;kff1206&quot;: &quot;tripkpl&quot;,<br>    &quot;kff1207&quot;: &quot;lp100km&quot;,<br>    &quot;kff1208&quot;: &quot;triplp100km&quot;,<br>    &quot;kff120c&quot;: &quot;tripdistance&quot;,<br>    &quot;kff1214&quot;: &quot;O2 Volts Bank 1 sensor 1&quot;,<br>    &quot;kff1215&quot;: &quot;O2 Volts Bank 1 sensor 2&quot;,<br>    &quot;kff1216&quot;: &quot;O2 Volts Bank 1 sensor 3&quot;,<br>    &quot;kff1217&quot;: &quot;O2 Volts Bank 1 sensor 4&quot;,<br>    &quot;kff1218&quot;: &quot;O2 Volts Bank 2 sensor 1&quot;,<br>    &quot;kff1219&quot;: &quot;O2 Volts Bank 2 sensor 2&quot;,<br>    &quot;kff121a&quot;: &quot;O2 Volts Bank 2 sensor 3&quot;,<br>    &quot;kff121b&quot;: &quot;O2 Volts Bank 2 sensor 4&quot;,<br>    &quot;kff1220&quot;: &quot;accelerometerx&quot;,<br>    &quot;kff1221&quot;: &quot;accelerometery&quot;,<br>    &quot;kff1222&quot;: &quot;accelerometerz&quot;,<br>    &quot;kff1223&quot;: &quot;accelerometertotal&quot;,<br>    &quot;kff1225&quot;: &quot;torque&quot;,<br>    &quot;kff1226&quot;: &quot;hpwheels&quot;,<br>    &quot;kff122d&quot;: &quot;0-60mph Time&quot;,<br>    &quot;kff122e&quot;: &quot;0-100kph Time&quot;,<br>    &quot;kff122f&quot;: &quot;1/4 mile time&quot;,<br>    &quot;kff1230&quot;: &quot;1/8 mile time&quot;,<br>    &quot;kff1237&quot;: &quot;speeddiffobdgps&quot;,<br>    &quot;kff1238&quot;: &quot;voltageobdadapter&quot;,<br>    &quot;kff1239&quot;: &quot;gpsaccurracy&quot;,<br>    &quot;kff123a&quot;: &quot;gpssats&quot;,<br>    &quot;kff123b&quot;: &quot;gpsbearing2&quot;,<br>    &quot;kff1240&quot;: &quot;O2 Sensor1 wide-range Voltage&quot;,<br>    &quot;kff1241&quot;: &quot;O2 Sensor2 wide-range Voltage&quot;,<br>    &quot;kff1242&quot;: &quot;O2 Sensor3 wide-range Voltage&quot;,<br>    &quot;kff1243&quot;: &quot;O2 Sensor4 wide-range Voltage&quot;,<br>    &quot;kff1244&quot;: &quot;O2 Sensor5 wide-range Voltage&quot;,<br>    &quot;kff1245&quot;: &quot;O2 Sensor6 wide-range Voltage&quot;,<br>    &quot;kff1246&quot;: &quot;O2 Sensor7 wide-range Voltage&quot;,<br>    &quot;kff1247&quot;: &quot;O2 Sensor8 wide-range Voltage&quot;,<br>    &quot;kff1249&quot;: &quot;airfuelratiomeasured&quot;,<br>    &quot;kff124a&quot;: &quot;Tilt(x)&quot;,<br>    &quot;kff124b&quot;: &quot;Tilt(y)&quot;,<br>    &quot;kff124c&quot;: &quot;Tilt(z)&quot;,<br>    &quot;kff124d&quot;: &quot;airfuelratiocommanded&quot;,<br>    &quot;kff124f&quot;: &quot;0-200kph Time&quot;,<br>    &quot;kff1257&quot;: &quot;CO₂ in g/km (Instantaneous)&quot;,<br>    &quot;kff1258&quot;: &quot;CO₂ in g/km (Average)&quot;,<br>    &quot;kff125a&quot;: &quot;fuelflowminute&quot;,<br>    &quot;kff125c&quot;: &quot;fuelcosttrip&quot;,<br>    &quot;kff125d&quot;: &quot;fuelflowhour&quot;,<br>    &quot;kff125e&quot;: &quot;60-120mph Time&quot;,<br>    &quot;kff125f&quot;: &quot;60-80mph Time&quot;,<br>    &quot;kff1260&quot;: &quot;40-60mph Time&quot;,<br>    &quot;kff1261&quot;: &quot;80-100mph Time&quot;,<br>    &quot;kff1263&quot;: &quot;Average trip speed(whilst moving only)&quot;,<br>    &quot;kff1264&quot;: &quot;100-0kph Time&quot;,<br>    &quot;kff1265&quot;: &quot;60-0mph Time&quot;,<br>    &quot;kff1266&quot;: &quot;Trip Time(Since journey start)&quot;,<br>    &quot;kff1267&quot;: &quot;Trip time(whilst stationary)&quot;,<br>    &quot;kff1268&quot;: &quot;Trip Time(whilst moving)&quot;,<br>    &quot;kff1269&quot;: &quot;volumetricefficiencycalc&quot;,<br>    &quot;kff126a&quot;: &quot;Distance to empty (Estimated)&quot;,<br>    &quot;kff126b&quot;: &quot;Fuel Remaining (Calculated from vehicle profile)&quot;,<br>    &quot;kff126d&quot;: &quot;Cost per mile/km (Instant)&quot;,<br>    &quot;kff126e&quot;: &quot;Cost per mile/km (Trip)&quot;,<br>    &quot;kff1270&quot;: &quot;Barometer (on Android device)&quot;,<br>    &quot;kff1271&quot;: &quot;Fuel used (trip)&quot;,<br>    &quot;kff1272&quot;: &quot;Average trip speed(whilst stopped or moving)&quot;,<br>    &quot;kff1273&quot;: &quot;Engine kW (At the wheels)&quot;,<br>    &quot;kff1275&quot;: &quot;80-120kph Time&quot;,<br>    &quot;kff1276&quot;: &quot;60-130mph Time&quot;,<br>    &quot;kff1277&quot;: &quot;0-30mph Time&quot;,<br>    &quot;kff5201&quot;: &quot;Miles Per Gallon(Long Term Average)&quot;,<br>    &quot;kff5202&quot;: &quot;Kilometers Per Litre(Long Term Average)&quot;,<br>    &quot;kff5203&quot;: &quot;Litres Per 100 Kilometer(Long Term Average)&quot;<br>};<br><br>const client = new InfluxDBClient({ host, token, database });<br><br>export const handler = async (event) =&gt; {<br>  console.log(event);<br>    const queryParams = event.queryStringParameters || {};<br><br>    let keys = {};<br>    for (const k in queryParams) {<br>        if (Object.hasOwnProperty.call(queryParams, k) &amp;&amp; /^k/.test(k)) {<br>            const val = parseFloat(queryParams[k]);<br>            const name = PID_DICT[k] || k;<br>            keys[name] = val;<br>        }<br>    }<br><br>    console.log(&#39;Parsed queryString parameters:&#39;, keys);<br><br>    try {<br>        const point = Point.measurement(measurement).setFields(keys);<br><br>        await client.write(point, database);<br>        console.log(&#39;Wrote point to InfluxDB&#39;);<br><br>        return {<br>            statusCode: 200,<br>            body: &#39;OK!&#39;,<br>        };<br>    } catch (err) {<br>        console.error(&#39;Error writing data to InfluxDB:&#39;, err);<br>        return {<br>            statusCode: 500,<br>            body: &#39;Internal Server Error&#39;,<br>        };<br>    }<br>};</pre><p>The OBD device gives each sensor a specific key as part of the query parameters that are sent, so a dictionary is used to map it back to a human-readable key. The Node.js library of Influx is used to create a data point with all sensor data and send it to the Influx Serverless endpoint.</p><h4>T-test and hypothesis testing</h4><p>I asked GPT-4 how I should prove or refute if the coolant temperature had changed significantly before and after a specific fix. It mentioned hypothesis testing, so I went to YouTube and other resources to understand the concepts.</p><p>I knew it was not enough to just feel like the overheating was resolved. Because the Jimny was overheating only on extreme slopes off-road, I knew it wouldn’t be easy to determine if a proper fix had been applied just by trying out different scenarios. I would need to return to the same slope to test it, meaning I could only try a new potential fix once every weekend. Statistics seemed like the way to go, as it would also take into account minute temperature changes that the human eye wouldn’t notice.</p><p>Testing was done from June 19, 2024, to July 4, 2024, at the start of the hot Israeli summer, which usually ends at the start of September. I was confident that there wasn’t any drastic change in environmental temperature between data points, ensuring consistent results.</p><p>I suspected that the faulty component of the vehicle was the engine fan clutch. A viscous fan clutch, often found in automotive cooling systems, uses silicone oil for its stable viscosity over a wide range of temperatures. I was asked to make a video of my fan clutch on a hot day after a strenuous drive to see if it moved more than a quarter turn. If it did, it was faulty. My video showed that it was indeed moving freely when the engine was very hot, indicating it was faulty.</p><p>I decided to replace the fan clutch and radiator and see if the problem would be resolved.</p><p>My null hypothesis was that the mean coolant temperature before the fix was lower or equal to the temperature after the fix, and the alternative hypothesis was that it was greater.</p><h4>Hypothesis testing code</h4><p>I didn’t want to call the InfluxDB Rest API as I knew that after 30 days, they recycle the data in their free tier. I exported all the data to a CSV file and deleted the GPS data for privacy issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rEO5mFRUzB1JWlmBG-Gypw.png" /><figcaption>InfluxDB data explorer</figcaption></figure><p>In today’s world, Python has triumphed over other languages for coding mathematics, so I used it. The first step was to convert the CSV to a Pandas DataFrame for easy manipulation.</p><pre>import pandas as pd<br>import seaborn as sns<br>import matplotlib.pyplot as plt<br>from datetime import datetime<br>import pytz<br>from scipy.stats import ttest_ind<br>import numpy as np<br><br># Load the data<br>data = pd.read_csv(&#39;./influxdata_no_gps.csv&#39;)</pre><p>I also knew that temperatures below 80 degrees Celsius were not relevant because the car’s thermostat engages only at 82 degrees. I wanted to create a graph of the engine’s coolant temperature over time to visualize the changes before and after the fix. Finally, I needed to smooth the data because when the car is turned off and left for a few minutes or more, the coolant temperature drops down to around 25 degrees Celsius, which is room temperature. Without smoothing the data, the graph would have sharp, irregular fluctuations that do not accurately represent the true temperature trends.</p><pre># Filter data to include only temperatures in the 80-120 range<br>data = data[(data[&#39;coolanttemp&#39;] &gt;= 80) &amp; (data[&#39;coolanttemp&#39;] &lt;= 120)]<br><br># Define the cutoff datetime with UTC timezone<br>cutoff = datetime(2024, 6, 26, 11, 15, tzinfo=pytz.UTC)<br><br># Split the data into before and after the cutoff<br>before_cutoff = data[data[&#39;time&#39;] &lt; cutoff].copy()<br>after_cutoff = data[data[&#39;time&#39;] &gt;= cutoff].copy()<br><br># Apply rolling mean to smooth out the curves, using a window of 5<br>before_cutoff.loc[:, &#39;smooth_coolanttemp&#39;] = before_cutoff[&#39;coolanttemp&#39;].rolling(window=5).mean()<br>after_cutoff.loc[:, &#39;smooth_coolanttemp&#39;] = after_cutoff[&#39;coolanttemp&#39;].rolling(window=5).mean()<br><br># Plotting the data<br>plt.figure(figsize=(14, 7))<br><br># Plot before cutoff<br>sns.lineplot(x=&#39;time&#39;, y=&#39;smooth_coolanttemp&#39;, data=before_cutoff, label=&#39;Before 26 June 2024 11:15&#39;)<br><br># Plot after cutoff<br>sns.lineplot(x=&#39;time&#39;, y=&#39;smooth_coolanttemp&#39;, data=after_cutoff, label=&#39;After 26 June 2024 11:15&#39;)<br><br>plt.title(&#39;Coolant Temperature Over Time (Smoothed)&#39;)<br>plt.xlabel(&#39;Time&#39;)<br>plt.ylabel(&#39;Coolant Temperature (°C)&#39;)<br>plt.legend()<br>plt.xticks(rotation=45)<br>plt.ylim(80, 120)<br>plt.show()</pre><p>For the car, I replaced the fan clutch with a new original Suzuki fan clutch and replaced the radiator, which was dirty and probably needed a refresh. I prefer replacing parts rather than refurbishing them, as buying new ones isn’t that expensive.</p><h4>Results Before and After Smoothing</h4><p>Before smoothing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GfjqI6Ngtw0sOSPSKgOnzA.png" /><figcaption>Before smoothing</figcaption></figure><p>After smoothing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eM3E4-0a_LoBIjvfHZvjYA.png" /><figcaption>After smoothing</figcaption></figure><p>The three occurrences where the coolant temperature reached more than 110°C were all on the same infamous slope. You can see that the same slope that produced 115–116°C before the fix produced only 111°C after the fix. This is a good indication that the specific fix did something positive.</p><p>I also wanted to see the other sensor data in relation to the coolant temperature:</p><pre># List of other sensors to plot against coolant temperature<br>other_sensors = [<br>    &#39;Barometer (on Android device)&#39;, &#39;Engine kW (At the wheels)&#39;, &#39;Intake Manifold Pressure&#39;,&#39;Turbo Boost &amp; Vacuum Gauge&#39;,<br>    &#39;accelerometertotal&#39;, &#39;hpwheels&#39;, &#39;rpm&#39;, &#39;hpwheels&#39;, &#39;throttlepos&#39;, <br>    &#39;torque&#39;<br>]<br><br># Plot scatter plots for each sensor against coolant temperature<br>for sensor in other_sensors:<br>    if sensor in data.columns:<br>        plt.figure(figsize=(10, 6))<br>        sns.scatterplot(x=&#39;coolanttemp&#39;, y=sensor, data=data)<br>        plt.title(f&#39;Coolant Temperature vs {sensor.replace(&quot;_&quot;, &quot; &quot;).title()}&#39;)<br>        plt.xlabel(&#39;Coolant Temperature (°C)&#39;)<br>        plt.ylabel(sensor.replace(&quot;_&quot;, &quot; &quot;).title())<br>        plt.show()</pre><p>The results showed some interesting relations that made sense:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m7M9B1I32dAKJCK373dLtQ.png" /><figcaption>coolant temprature vs Barometer</figcaption></figure><p>The slope ended in a high-altitude mountain range, and the overheating happened there. As elevation increases, atmospheric pressure decreases, which made sense since the overheating occurred only when I pushed the car through mountains to higher altitudes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vTxdk1vgTQzIzhazk0tkwQ.png" /><figcaption>Coolant temperature vs Throttlepos</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AIqqaBtd_SIOAbwYjMCh2Q.png" /><figcaption>Coolant temperature vs Torque</figcaption></figure><p>The overheating happened when I stopped the car at the end of a slope. It showed that the more I pushed the throttle for gasoline to enter, the more the engine produced power, making the car move and allowing air to cool the coolant inside the radiator. This indicated that the problem occurred only at slow speeds when there wasn’t enough airflow to cool the radiator’s coolant due to a faulty fan clutch.</p><h4>Categorizing the Driving Conditions</h4><p>To better analyze the data, I categorized driving conditions based on the speed of driving, as I knew the speed was a significant factor in overheating.</p><pre># Define the driving conditions<br>def categorize_driving_condition(row):<br>    if row[&#39;speedobd&#39;] &lt;= 10:<br>        return &#39;offroad&#39;<br>    elif row[&#39;speedobd&#39;] &gt; 10 and row[&#39;speedobd&#39;] &lt;= 30:<br>        return &#39;slow&#39;<br>    elif row[&#39;speedobd&#39;] &gt; 30 and row[&#39;speedobd&#39;] &lt;= 60:<br>        return &#39;urban&#39;<br>    else:<br>        return &#39;highway&#39;<br><br># Apply the categorization<br>data[&#39;driving_condition&#39;] = data.apply(categorize_driving_condition, axis=1)<br>before_cutoff[&#39;driving_condition&#39;] = before_cutoff.apply(categorize_driving_condition, axis=1)<br>after_cutoff[&#39;driving_condition&#39;] = after_cutoff.apply(categorize_driving_condition, axis=1)<br><br># Function to calculate statistics and perform tests<br>def analyze_condition(condition):<br>    before = before_cutoff[before_cutoff[&#39;driving_condition&#39;] == condition][&#39;coolanttemp&#39;]<br>    after = after_cutoff[after_cutoff[&#39;driving_condition&#39;] == condition][&#39;coolanttemp&#39;]<br>    <br>    mean_before = before.mean()<br>    mean_after = after.mean()<br>    std_before = before.std()<br>    std_after = after.std()<br>    <br>    t_stat, p_value = ttest_ind(before, after, alternative=&#39;greater&#39;)<br>    cohen_d = (mean_after - mean_before) / np.sqrt((std_before**2 + std_after**2) / 2)<br>    <br>    return mean_before, mean_after, t_stat, p_value, cohen_d<br><br># Analyze each driving condition<br>conditions = [&#39;offroad&#39;, &#39;slow&#39;, &#39;urban&#39;, &#39;highway&#39;]<br>results = {}<br><br>for condition in conditions:<br>    mean_before, mean_after, t_stat, p_value, cohen_d = analyze_condition(condition)<br>    results[condition] = {<br>        &#39;mean_before&#39;: mean_before,<br>        &#39;mean_after&#39;: mean_after,<br>        &#39;t_stat&#39;: t_stat,<br>        &#39;p_value&#39;: p_value,<br>        &#39;cohen_d&#39;: cohen_d<br>    }<br><br># Print the results<br>for condition, result in results.items():<br>    print(f&quot;Driving Condition: {condition}&quot;)<br>    print(f&quot;Mean Before Fix: {result[&#39;mean_before&#39;]:.2f}&quot;)<br>    print(f&quot;Mean After Fix: {result[&#39;mean_after&#39;]:.2f}&quot;)<br>    print(f&quot;T-statistic: {result[&#39;t_stat&#39;]:.2f}, P-value: {result[&#39;p_value&#39;]}&quot;)<br>    print(f&quot;Effect Size (Cohen&#39;s d): {result[&#39;cohen_d&#39;]:.2f}&quot;)<br>    print(f&quot;Mean difference: {result[&#39;mean_after&#39;] - result[&#39;mean_before&#39;]:.2f}&quot;)<br>    print(&#39;\n&#39;)</pre><h4>Results</h4><p>The results confirmed the alternative hypothesis. After the fix, the mean coolant temperature dropped, especially off-road. On highways, Cohen’s d was small, and the mean difference was less than 0.5°C, which made sense since the problem did not exist at high speeds. The fix not only helped the coolant temperature drop off-road but also during urban driving.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*DbxddLO6NHEj-r-0icoPgg.png" /></figure><p>These results clearly indicate that the replacement of the fan clutch and radiator helped reduce the engine’s coolant temperature by an average of 2.5°C, maintaining a healthier engine and a happier me.</p><p>You can see the full code on <a href="https://github.com/talkl/JimnyTorqueOBD/blob/main/TorqueOBD.ipynb">Github</a> and feel free to comment or ask any questions.</p><p>Until next time! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ab4e2e19112" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React beautiful dnd with Antd list]]></title>
            <link>https://medium.com/@talkleiner/react-beautiful-dnd-with-antd-list-19ed6d77ae42?source=rss-9d85f9ed516d------2</link>
            <guid isPermaLink="false">https://medium.com/p/19ed6d77ae42</guid>
            <category><![CDATA[ant-design]]></category>
            <category><![CDATA[versatile]]></category>
            <category><![CDATA[construction-tech]]></category>
            <category><![CDATA[react-beautiful-dnd]]></category>
            <category><![CDATA[power-bi]]></category>
            <dc:creator><![CDATA[Tal Kleiner]]></dc:creator>
            <pubDate>Sun, 06 Sep 2020 15:17:38 GMT</pubDate>
            <atom:updated>2020-09-06T15:17:38.589Z</atom:updated>
            <content:encoded><![CDATA[<p>How I integrated a drag and drop experience into an ant design list react component</p><p>Recently I was asked at work to create an interactive way of selecting <a href="https://powerbi.microsoft.com/en-us/">power bi</a> widgets into a collection of widgets to be sent to our customers as an email report that can later be deep linked into our web app. The request was to have two lists, so we pick widgets from the left side and drag and drop to a collection which is a list on the right side. We already had the list component built by a colleague of mine with <a href="https://ant.design/">Antd</a> but the drag and drop experience was lacking. I searched the internet and found out about <a href="https://react-dnd.github.io/react-dnd/">react-dnd</a> and <a href="https://github.com/atlassian/react-beautiful-dnd">React beautiful dnd</a> (will be referred to as “rbdnd” from now on) and decided to use rbdnd since it seemed a faster integration which is what we usually need in our startup.</p><h4>Motivation for this article</h4><p>When I started writing the code I searched for a quick Medium article or something similar to guide me through the process. What I found was something vague mentioned in the issue section of github and a github gist which lacks the full code of the implementation. I had experienced some head-scratcher bugs while writing the code so I wanted to save you some time and share the things I learned in the process. If you only want the code you can check it out in <a href="https://codesandbox.io/s/react-beautiful-dnd-with-antd-list-71ju3">Codesandbox</a>.</p><h3>Challenges</h3><p>The following are esoteric problems I encountered during the development of the feature. I assume you already watched the <a href="https://egghead.io/courses/beautiful-and-accessible-drag-and-drop-with-react-beautiful-dnd">crash course</a> that react beautiful dnd published in egghead.io and have a basic understanding of how to implement rbdnd.</p><h4>Problem: Passing InnerRef</h4><p>Rbdnd &lt;Draggable /&gt; and &lt;Droppable /&gt; components both require an <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement">HTMLElement</a>. This is done using the innerRef property on the DraggableProvided and DroppableProvided objects. A common error is the following:</p><pre>&lt;Draggable draggableId=&quot;draggable-1&quot; index={0}&gt;<br>  {(provided, snapshot) =&gt; (<br>    &lt;List<br>      ref={provided.innerRef}<br>      {...provided.droppableProps}<br>    /&gt;<br>  )}<br>&lt;/Draggable&gt;</pre><p>In this example we are calling provided.innerRef with an <em>instance</em> of the react class componentList and not the DOM node.</p><h4>Solution: Wrapping antd list with a div</h4><p>The solution is to wrap antd list with a div and pass the droppable props to the div, like so:</p><pre>&lt;Droppable droppableId=&quot;droppable-1&quot; index={0}&gt;<br>  {(provided, snapshot) =&gt; (<br>    <strong>&lt;div<br>      ref={provided.innerRef}<br>      {...provided.droppableProps}<br>    &gt;</strong><br>      &lt;List/&gt;</pre><pre>&lt;/div&gt;<br>  )}<br>&lt;/Droppable&gt;</pre><p>Same thing with the antd item. Wrap it with a div and pass the draggable props accordingly.</p><h4>Problem: Performance issue with a list of hundreds of items</h4><p>Our antd list items are rectangles with text and an image. A list consists of hundreds of items in my case. When I first rendered the list, the browser wanted to eager load all the images in the list, which became strenuous for my Mac to handle.</p><figure><img alt="antd list eager load hundreds of images performance issue" src="https://cdn-images-1.medium.com/max/600/1*ZRHhNOSuyP_bHxNOKtYhng.gif" /></figure><h4>Solution: Use antd list pagination feature</h4><p>Luckily antd list already has a pagination feature which lazy loads the content of the items only after the page is selected or the results are filtered.</p><pre>&lt;List<br>   pagination={{<br>   <strong>current: itemsPage,</strong><br>   pageSize: this.itemsPageSize,<br>   <strong>onChange: this.onListPagination.bind(this, ListsIds.<em>Droppable</em>),</strong><br>   showTotal: (total: number, range: [number, number]) =&gt; {<br>     return `${range[0]}-${range[1]} of ${total} items`;<br>   },<br> }}<br>/&gt;</pre><p>I’m saving the current page for both lists in the state of the component since I will be using it later for other calculations.</p><pre>@autobind<br>private onListPagination(listId: ListsIds, page: number) {<br>  const { pagination } = this.state;<br>  const updatedPaginationState = listId === ListsIds.<em>Droppable </em>? {<br>    itemsPage: page,<br>    } : {<br>    selectedPage: page,<br>  };<br>  this.setState({<br>    pagination: {<br>      ...pagination,<br>      ...updatedPaginationState<br>    }<br>  });<br>}</pre><h4>Problem: Non consecutive draggable indexes</h4><p>Rbdnd explicitly enumerates the rules to handle the item’s indexes.</p><p>Rules:</p><ul><li>Must be unique within a &lt;Droppable /&gt; (no duplicates)</li><li>Must be consecutive. [0, 1, 2] and not [1, 2, 8]</li><li>Indexes do not need to start from 0 (this is often the case in <a href="https://github.com/atlassian/react-beautiful-dnd/blob/master/docs/patterns/virtual-lists.md">virtual lists</a>)</li></ul><p>I experienced some weird bugs in the beginning with a development warning message:</p><figure><img alt="warning message from rbdnd" src="https://cdn-images-1.medium.com/max/1024/1*1vV5M-5Vm4JFTDIzJRZQNA.png" /><figcaption>rbdbd warning message</figcaption></figure><h4>Solution: use rowKey property of antd list</h4><p>We can tell Antd list that the row it renders can be identified by the item’s id, which is the same id that is passed to rbdnd. That way rbdnd and antd are both synced about what items are rendered at each moment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xIw0Hvt27PVqXDXehxdgNg.png" /><figcaption>antd rowKey prop</figcaption></figure><pre>rowKey={(item: Item&lt;IMasterWidget&gt;): string =&gt; item.id}</pre><h4>Problem: calculating the index to remove and add items from the list</h4><p>We need to reorder or move the item according to the user’s action in the onDragEnd Event. The following interfaces provide us with the destination and the source.</p><pre>export interface DraggableLocation {<strong><br></strong>    droppableId: DroppableId;<br><strong>    index: number;<br></strong>}</pre><pre>export interface DragStart extends BeforeCapture {<br>    type: TypeId;<br><strong>    source: DraggableLocation;</strong><br>}</pre><pre>export interface DragUpdate extends DragStart {<br>    // may not have any destination (drag to nowhere)<br><strong>    destination?: DraggableLocation;</strong><br>    // populated when a draggable is dragging over another in combine mode<br>    combine?: Combine;<br>}</pre><pre>export interface <strong>DropResult</strong> extends DragUpdate {<br>    reason: DropReason;<br>}</pre><p>The problem is that the index of the draggable location is the index of the rendered Antd list item, which is determined by the pagination page size that we passed to the Antd list component, if you remember from earlier:</p><pre>&lt;List<br>   pagination={{<br>   current: itemsPage,<br><strong>   pageSize: this.itemsPageSize,</strong><br>   onChange: this.onListPagination.bind(this, ListsIds.<em>Droppable</em>),<br>   showTotal: (total: number, range: [number, number]) =&gt; {<br>     return `${range[0]}-${range[1]} of ${total} items`;<br>   },<br> }}<br>/&gt;</pre><p>So for example if we defined a page size of 5 and we are currently dragging the first item of that list in page number 3, the index passed to source will be 0 but the real index is 11 (10 items in pages 1–2 and the 11th item will be our first item in page 3).</p><h4>Solution: calculate shifted index</h4><p>we calculate the real index of the draggable in the Antd list by summing the number of rendered items until the current page, and adding the index of the draggable that we got from the “onDragEnd” event.</p><pre>@autobind<br>private calculateShiftedIndex(draggableLocation: DraggableLocation): number {<br>  const { pagination: { itemsPage, selectedPage } } = this.state;<br>  return draggableLocation.droppableId === ListsIds.<em>Droppable </em>?<br>    (itemsPage - 1) * this.itemsPageSize :<br>    (selectedPage - 1) * this.selectedPageSize;<br>}</pre><p>This method is called when removing item from a list and adding to another, like so:</p><pre>const [removed] = sourceClone.splice( <strong>this.calculateShiftedIndex(source)</strong> + source.index, 1);<br>destClone.splice( <strong>this.calculateShiftedIndex(destination)</strong> + destination.index, 0, removed);</pre><h4>Problem: Antd bug when removing last item of a page</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*9DIKb0oOOAhUuRs5Zx7HFQ.gif" /><figcaption>Antd automatically changes page</figcaption></figure><p>When removing items from a specific page in Antd list, when the page is emptied Antd will render the previous page with the items of that page. The problem is that the pagination callback is not fired:</p><pre>onChange: this.onListPagination.bind(this, ListsIds.<em>Droppable2</em>)</pre><p>This causes a bug where the current page of a list isn’t updated when emptying a page from items and the shifted index will be calculated in an erroneous way.</p><h4>Solution: Manually change page when emptying a page from items</h4><p>I had to write a method that is invoked when onDragEnd event is fired. The method calculates whether a page has been emptied and if so update the current page in the react’s component state accordingly.</p><pre>@autobind<br>private calculateShiftedPagination&lt;T&gt;(sourceId: string, sourceClone: Item&lt;T&gt;[]): IListsPagination {<br>  const { pagination: { itemsPage, selectedPage } } = this.state;<br>  let pagination = {...this.state.pagination};<br>  const sourceLength = sourceClone.length;<br>  if (sourceId === ListsIds.<em>Droppable</em>) {<br>    <strong>const didRemovedLastItemFromPage: boolean = (((itemsPage - 1) * this.itemsPageSize) - sourceLength) === 0 &amp;&amp;<br>    sourceLength &gt; 0;</strong><br>    if (didRemovedLastItemFromPage) {<br>      pagination = {<br>        ...pagination,<br>        itemsPage: itemsPage - 1,<br>      }<br>    }<br>  } else if (sourceId === ListsIds.<em>Droppable2</em>) {<br>    <strong>const didRemovedLastItemFromPage: boolean = (((selectedPage - 1) * this.selectedPageSize) - sourceLength) === 0 &amp;&amp;<br>    sourceLength &gt; 0;</strong><br>    if (didRemovedLastItemFromPage) {<br>      pagination = {<br>        ...pagination,<br>        selectedPage: selectedPage - 1,<br>      }<br>    }<br>  }<br>  return pagination;<br>}</pre><h3>Conclusion</h3><p>It was a satisfying experience to manage successfully all these little unexpected bugs that came my way. If you have any questions don’t hesitate to ask. Also, if you are interested in the challenges that we face in our construction tech startup and want to know more, please visit our website <a href="https://www.versatile.ai/">versatile.ai</a>.</p><p>And last but not least , here is a <a href="https://codesandbox.io/s/react-beautiful-dnd-with-antd-list-71ju3?fontsize=14&amp;hidenavigation=1&amp;theme=dark">Codesandbox</a> if you want to see the code in action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*utQN9MxqM4MCS47HLuSKIw.gif" /><figcaption>final result</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19ed6d77ae42" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>