3 Commits
15 changed files with 394 additions and 96 deletions

No files matched your search

+5 -2
View File
@@ -13,8 +13,11 @@ android {
applicationId = "com.racingapp.pitlog"
minSdk = 26
targetSdk = 36
versionCode = 3
versionName = "0.003"
// Three digits. versionCode is that number with the dot removed.
// A fix adds 0.001. One feature adds 0.010. A batch of features adds 0.100.
// The release tag is v plus versionName, such as v0.013.
versionCode = 43
versionName = "0.043"
}
buildTypes {
@@ -1,6 +1,8 @@
package com.racingapp.pitlog.model
import java.util.Locale
import kotlin.math.abs
import kotlin.math.roundToInt
fun sanitizeSignedDecimal(raw: String, wholeDigits: Int, fractionDigits: Int): String {
val negative = raw.trimStart().startsWith('-')
@@ -31,6 +33,72 @@ fun parseDecimal(raw: String): Double? {
return trimmed.toDoubleOrNull()
}
fun sanitizeInches(raw: String, signed: Boolean = false): String {
val negative = signed && raw.trimStart().startsWith('-')
val source = raw.trim().removePrefix("-").removePrefix("+").replace(',', '.')
val out = StringBuilder()
var slash = false
var dot = false
var space = false
var digits = 0
for (ch in source) {
when {
ch.isDigit() -> {
val limit = when {
slash || dot -> if (dot) 4 else 2
else -> 2
}
if (digits < limit) {
out.append(ch)
digits++
}
}
ch == '/' && !slash && !dot && out.isNotEmpty() && !out.endsWith(' ') -> {
slash = true
digits = 0
out.append('/')
}
ch == '.' && !dot && !slash && !space -> {
dot = true
digits = 0
out.append('.')
}
ch == ' ' && !space && !slash && !dot && digits > 0 -> {
space = true
digits = 0
out.append(' ')
}
}
}
val text = out.toString()
if (text.isEmpty()) return if (negative) "-" else ""
return if (negative) "-$text" else text
}
fun parseInches(raw: String): Double? {
val trimmed = raw.trim().removeSuffix(" ")
if (trimmed.isEmpty() || trimmed == "-" || trimmed.endsWith("/") || trimmed.endsWith(".")) return null
val negative = trimmed.startsWith("-")
val body = trimmed.removePrefix("-").trim()
val value = if (body.contains("/")) parseFraction(body) else parseDecimal(body)
value ?: return null
return if (negative) -value else value
}
fun formatInches(value: Double?): String {
if (value == null) return ""
val negative = value < 0
val magnitude = abs(value)
val scaled = magnitude * 64.0
val nearest = scaled.roundToInt()
val body = if (abs(scaled - nearest) <= 0.04) {
fractionInches(nearest)
} else {
String.format(Locale.US, "%.3f", magnitude).trimEnd('0').trimEnd('.')
}
return if (negative && body != "0") "-$body" else body
}
fun parseIntField(raw: String): Int? = raw.trim().toIntOrNull()
fun formatPsi(value: Double?): String =
@@ -52,15 +120,48 @@ fun formatDegrees(value: Double?): String =
fun formatStagger(value: Double?): String {
if (value == null) return "—"
return String.format(Locale.US, "%.2f", value).trimEnd('0').trimEnd('.')
return formatInches(value)
}
fun psiField(value: Double?): String =
if (value == null) "" else String.format(Locale.US, "%.1f", value)
fun staggerField(value: Double?): String {
if (value == null) return ""
return String.format(Locale.US, "%.2f", value).trimEnd('0').trimEnd('.')
fun staggerField(value: Double?): String = formatInches(value)
private fun parseFraction(body: String): Double? {
val parts = body.split(' ').filter { it.isNotEmpty() }
val whole: Double
val token: String
when (parts.size) {
1 -> {
whole = 0.0
token = parts[0]
}
2 -> {
whole = parts[0].toDoubleOrNull() ?: return null
token = parts[1]
}
else -> return null
}
val bits = token.split('/')
if (bits.size != 2 || bits[1].isEmpty()) return null
val numerator = bits[0].toDoubleOrNull() ?: return null
val denominator = bits[1].toDoubleOrNull() ?: return null
if (denominator == 0.0) return null
return whole + numerator / denominator
}
private fun fractionInches(sixtyFourths: Int): String {
val whole = sixtyFourths / 64
var numerator = sixtyFourths % 64
var denominator = 64
if (numerator == 0) return whole.toString()
while (numerator % 2 == 0) {
numerator /= 2
denominator /= 2
}
val fraction = "$numerator/$denominator"
return if (whole == 0) fraction else "$whole $fraction"
}
fun intField(value: Int?): String = value?.toString().orEmpty()
@@ -123,7 +123,7 @@ data class RunForm(
if (sheet.cold.any() || sheet.hot.any()) return true
if (sheet.heat.values.any { it.any() }) return true
if (parseIntField(laps) != null || parseIntField(finish) != null) return true
if (parseDecimal(stagger) != null) return true
if (parseInches(stagger) != null) return true
if (tireSet.isNotBlank() || notes.isNotBlank()) return true
return handling != null || handlingWhere != null
}
@@ -137,7 +137,7 @@ data class RunForm(
tireSet = tireSet.trim(),
laps = parseIntField(laps),
finish = parseIntField(finish),
staggerInches = parseDecimal(stagger),
staggerInches = parseInches(stagger),
coldLf = sheet.cold.lf,
coldRf = sheet.cold.rf,
coldLr = sheet.cold.lr,
@@ -28,22 +28,61 @@ fun setupLines(sheet: SetupSheet): List<String> = buildList {
"RR" to sheet.weightRr,
).mapNotNull { (corner, pounds) -> pounds?.let { "$corner $it" } }
if (weights.isNotEmpty()) add("Weights ${weights.joinToString(" ")} lb")
weightSplit(sheet.weightLf, sheet.weightRf, sheet.weightLr, sheet.weightRr)?.let { add("From the weights $it") }
addAll(scaleLines(sheet.weightLf, sheet.weightRf, sheet.weightLr, sheet.weightRr))
sheet.rideHeight?.let { add("Ride height ${inches(it)} in") }
sheet.pinion?.let { add("Pinion ${formatDegrees(it)}°") }
sheet.brakeFront?.let { add("Front brake ${onePlace(it)}%") }
}
fun weightSplit(lf: Int?, rf: Int?, lr: Int?, rr: Int?): String? {
fun scaleLines(lf: Int?, rf: Int?, lr: Int?, rr: Int?): List<String> {
val reading = scaleReading(lf, rf, lr, rr) ?: return emptyList()
return listOf(
"Total ${reading.total} lb",
"Left ${pair(reading.left, reading.leftPercent)}",
"Front ${pair(reading.front, reading.frontPercent)}",
"Rear ${pair(reading.rear, reading.rearPercent)}",
"Cross ${pair(reading.cross, reading.crossPercent)}",
"Rear bite ${reading.rearBite}",
)
}
private data class ScaleReading(
val total: Int,
val left: Int,
val leftPercent: Double,
val front: Int,
val frontPercent: Double,
val rear: Int,
val rearPercent: Double,
val cross: Int,
val crossPercent: Double,
val rearBite: Int,
)
private fun scaleReading(lf: Int?, rf: Int?, lr: Int?, rr: Int?): ScaleReading? {
if (lf == null || rf == null || lr == null || rr == null) return null
val total = lf + rf + lr + rr
if (total <= 0) return null
val left = (lf + lr) * 100.0 / total
val rear = (lr + rr) * 100.0 / total
val cross = (rf + lr) * 100.0 / total
return "Left ${onePlace(left)}% Rear ${onePlace(rear)}% Cross ${onePlace(cross)}%"
val left = lf + lr
val front = lf + rf
val rear = lr + rr
val cross = rf + lr
return ScaleReading(
total = total,
left = left,
leftPercent = left * 100.0 / total,
front = front,
frontPercent = front * 100.0 / total,
rear = rear,
rearPercent = rear * 100.0 / total,
cross = cross,
crossPercent = cross * 100.0 / total,
rearBite = lr - rr,
)
}
private fun pair(pounds: Int, percent: Double) = "$pounds lb, ${onePlace(percent)}%"
fun setupDiffs(before: SetupSheet, after: SetupSheet): List<String> = buildList {
changed(before.crossPercent, after.crossPercent, ::percent)?.let { add("Cross $it") }
changedInt(before.springLf, after.springLf, " lb")?.let { add("LF spring $it") }
@@ -63,18 +102,40 @@ fun setupDiffs(before: SetupSheet, after: SetupSheet): List<String> = buildList
changedInt(before.weightRf, after.weightRf, " lb")?.let { add("RF weight $it") }
changedInt(before.weightLr, after.weightLr, " lb")?.let { add("LR weight $it") }
changedInt(before.weightRr, after.weightRr, " lb")?.let { add("RR weight $it") }
addAll(scaleChanges(before, after))
changed(before.rideHeight, after.rideHeight) { "${inches(it)} in" }?.let { add("Ride height $it") }
changed(before.pinion, after.pinion) { "${formatDegrees(it)}°" }?.let { add("Pinion $it") }
changed(before.brakeFront, after.brakeFront) { "${onePlace(it)}%" }?.let { add("Front brake $it") }
}
private fun scaleChanges(before: SetupSheet, after: SetupSheet): List<String> {
val old = scaleReading(before.weightLf, before.weightRf, before.weightLr, before.weightRr)
val next = scaleReading(after.weightLf, after.weightRf, after.weightLr, after.weightRr)
if (old == null || next == null || old == next) return emptyList()
return buildList {
if (old.total != next.total) add("Total ${old.total} lb → ${next.total} lb")
if (old.left != next.left || onePlace(old.leftPercent) != onePlace(next.leftPercent)) {
add("Left ${pair(old.left, old.leftPercent)} → ${pair(next.left, next.leftPercent)}")
}
if (old.front != next.front || onePlace(old.frontPercent) != onePlace(next.frontPercent)) {
add("Front ${pair(old.front, old.frontPercent)} → ${pair(next.front, next.frontPercent)}")
}
if (old.rear != next.rear || onePlace(old.rearPercent) != onePlace(next.rearPercent)) {
add("Rear ${pair(old.rear, old.rearPercent)} → ${pair(next.rear, next.rearPercent)}")
}
if (old.cross != next.cross || onePlace(old.crossPercent) != onePlace(next.crossPercent)) {
add("Cross ${pair(old.cross, old.crossPercent)} → ${pair(next.cross, next.crossPercent)}")
}
if (old.rearBite != next.rearBite) add("Rear bite ${old.rearBite} → ${next.rearBite}")
}
}
private fun percent(value: Double): String = String.format(Locale.US, "%.1f%%", value)
private fun onePlace(value: Double): String =
String.format(Locale.US, "%.1f", value).trimEnd('0').trimEnd('.')
private fun inches(value: Double): String =
String.format(Locale.US, "%.3f", value).trimEnd('0').trimEnd('.')
private fun inches(value: Double): String = formatInches(value)
private fun changed(
before: Double?,
@@ -282,8 +282,8 @@ private fun swayBarTip(turns: Int?, handling: String): SetupTip? {
val tight = handling.equals(Handling.Tight.label, ignoreCase = true)
val loose = handling.equals(Handling.Loose.label, ignoreCase = true)
return when {
tight -> SetupTip("Sway bar", "Less bar.")
loose -> SetupTip("Sway bar", "More bar.")
tight -> SetupTip("Front roll stiffness", "Less front roll stiffness.")
loose -> SetupTip("Front roll stiffness", "More front roll stiffness.")
else -> null
}
}
@@ -299,8 +299,8 @@ private fun blockTip(left: Double?, right: Double?, handling: String, where: Str
val tight = handling.equals(Handling.Tight.label, ignoreCase = true)
val loose = handling.equals(Handling.Loose.label, ignoreCase = true)
return when {
tight -> SetupTip("Blocks", "Less block.")
loose -> SetupTip("Blocks", "More block.")
tight -> SetupTip("Rear roll stiffness", "Less rear roll stiffness.")
loose -> SetupTip("Rear roll stiffness", "More rear roll stiffness.")
else -> null
}
}
@@ -94,14 +94,22 @@ fun NumberField(
onValue: (String) -> Unit,
modifier: Modifier = Modifier,
decimal: Boolean = true,
inches: Boolean = false,
placeholder: String = "",
) {
OutlinedTextField(
value = value,
onValueChange = onValue,
label = { Text(label) },
placeholder = if (placeholder.isEmpty()) null else ({ Text(placeholder) }),
singleLine = true,
keyboardOptions = KeyboardOptions(
keyboardType = if (decimal) KeyboardType.Decimal else KeyboardType.Number,
capitalization = KeyboardCapitalization.None,
keyboardType = when {
inches -> KeyboardType.Uri
decimal -> KeyboardType.Decimal
else -> KeyboardType.Number
},
),
textStyle = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.SemiBold),
modifier = modifier,
@@ -2,6 +2,7 @@ package com.racingapp.pitlog.ui.guide
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
@@ -15,6 +16,7 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilterChip
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
@@ -175,26 +177,26 @@ private val handling = listOf(
"Middle, tight",
listOf(
Move("Take crossweight out.", "Once the car is square and the geometry is honest, a tight middle wants less crossweight."),
Move("Less block.", "A taller block under the leaves increases roll and tightens the entry and the middle. Over 3 inches cuts forward bite. String the rear after a block change, because the blocks and U-bolts shift."),
Move("Less rear roll stiffness.", "That is a thinner block under the leaves. A thicker block tightens the entry and the middle. Over 3 inches cuts forward bite. String the rear after a block change, because the blocks and U-bolts shift."),
Move("Let the front roll closer to the rear.", "A tight middle often means the rear wants to roll more than the front. Soften the right-front spring, or stiffen the left-front. A stiffer left-front does not work well above about 10 degrees of banking."),
Move("Read the left-rear temperature.", "If the left rear is the coolest tire, the rear spring split is too large and the right-rear spring is too stiff."),
Move("Less bar.", "Less bar if the car is tight. On a leaf-spring Camaro a bigger bar faded after a few laps. If more bar only helps a few laps, put it back and stiffen the front springs."),
Move("Less front roll stiffness.", "That is less bar on the all-thread. On a leaf-spring Camaro a stiffer bar faded after a few laps. If more front roll stiffness only helps a few laps, put it back and stiffen the front springs."),
),
),
HandlingCase(
"Middle, loose",
listOf(
Move("Add crossweight.", "Once alignment and balance are right, a loose middle wants more crossweight."),
Move("More block.", "A taller block tightens the entry and the middle. Stay at 3 inches or under, or forward bite falls off."),
Move("More rear roll stiffness.", "That is a thicker block. It tightens the entry and the middle. Stay at 3 inches or under, or forward bite falls off."),
Move("Ease a right-rear spring that is much stiffer than the left rear.", "If the front is rolling more than the rear, load piles onto the right rear."),
Move("More bar.", "More bar if the car is loose. The bar has to move freely in the stock saddles."),
Move("More front roll stiffness.", "That is more bar on the all-thread. The bar has to move freely in the stock saddles."),
Move("Do not add stagger to make it turn.", "Extra stagger used to free a tight middle shows up as loose off the corner under power."),
),
),
HandlingCase(
"Entry, tight",
listOf(
Move("Less block.", "More block tightens the entry as well as the middle."),
Move("Less rear roll stiffness.", "More rear roll stiffness tightens the entry as well as the middle."),
Move("Check right-front camber through the dive.", "If the nose dives hard, the right front loses camber and the push starts. Once it starts, it is hard to drive out of. The left front also loses camber in the dive. It wants about 1/2–1° positive while it is loaded. The right-front camber change through the dive and the roll should stay near zero."),
Move("Do not fix the entry with brake bias alone.", "Compare a light brake with a hard brake. If they feel the same, bias is not the problem."),
),
@@ -202,7 +204,7 @@ private val handling = listOf(
HandlingCase(
"Entry, loose",
listOf(
Move("More block.", "More block tightens the entry. Keep each block at 3 inches or under."),
Move("More rear roll stiffness.", "It tightens the entry. Keep each block at 3 inches or under."),
Move("Move brake bias forward.", "Too much rear brake loosens the car on a hard entry. A usual asphalt split is about 60–65% front and 35–40% rear, if the book allows an adjuster. The adjuster has to be under the dash or the hood, out of the driver's reach, on the tri-state book."),
Move("Take out rear steer to the right.", "If the right rear is farther back than the left rear as the car rolls in, the rear is steering right and the car gets loose."),
),
@@ -210,9 +212,7 @@ private val handling = listOf(
HandlingCase(
"Exit, tight",
listOf(
Move("Add stagger for the radius, then leave it.", "Too little stagger for the corner leaves the car tight getting off. On a spool both rear tires turn the same number of times, and stagger steers the middle when the axles are locked. Size it for the radius and the banking, then stop using it as a handling knob."),
Move("A locked rear and an open rear are different.", "On a spool or a welded rear, both tires turn the same number of times the whole corner, so stagger steers the middle. An open rear lets the tires turn at different speeds, so stagger does not steer the middle the same way. Wenatchee allows an open rear. Stateline is spool or welded. These books do not allow a Detroit Locker. A rear that unlocks in the middle and locks on power would be sized for the wider exit radius, which wants less stagger than a spool."),
Move("More banking wants a little less stagger.", "The same corner on a bank wants less stagger than it would on flat ground. Radius is still the big piece. About 10 degrees is roughly 1.5% less. About 20 degrees is roughly 6% less."),
Move("Add stagger for the radius, then leave it.", "Too little for the corner leaves the car tight getting off. Size it for the radius and the banking, then stop using it as a handling knob."),
),
),
HandlingCase(
@@ -227,11 +227,13 @@ private val handling = listOf(
private val starts = listOf(
Tip("Crossweight", "52–55% on a leaf-spring car. Less than a coil car usually wants."),
Tip("Front springs", "Rate each spring at the height it sits in the car. Replace a bent or tired one. Keep the split under about 100 lb. Softening the front adds front traction, so the cross has to come up or the car gets loose. If the front out-rolls the rear, stiffen the front springs and use less bar."),
Tip("Front springs", "Rate each spring at the height it sits in the car. Replace a bent or tired one. Keep the split under about 100 lb. Softening the front adds front traction, so the cross has to come up or the car gets loose. If the front out-rolls the rear, stiffen the front springs and use less front roll stiffness."),
Tip("Caster", "Top of the ball-joint line tilted back is positive. Tilted forward is negative. Positive caster holds a line. Too much makes the wheel heavy. Negative caster lets the car wander on the straight. A short track often wants about 2–4° of split, left front around 1–2° and right front around 3–5°. More banking wants less caster. A tighter radius wants more split. At mid-turn the wheel should pull slightly. Check the toe after you change caster."),
Tip("Blocks", "Under the leaves. More block tightens the entry and the middle. Over 3 inches cuts forward bite. South Sound allows steel leaves, at least four, with blocks, shackles, and sliders. The tri-state book allows steel or poly leaves and shackles."),
Tip("Sway bar", "Less bar if the car is tight. More bar if it is loose. The tri-state book allows a 1-1/4 inch bar in the stock saddles, adjusted with all-thread, no heim joints. South Sound's book does not list a bar."),
Tip("Stagger", "Right rear minus left rear, around the center of the tread, with a flexible 1/4-inch tape, at the cold pressure you will race. On a bias-ply tire, more air on the right, or less on the left, grows the stagger before you change tires. That rear-stagger gain takes cross out. More air that grows the right front adds cross. A tighter radius wants more. More banking wants a little less. Too much makes the car turn left on the straight, so the driver steers right and scrubs speed. On a bias-ply tire a sliding right rear heats, grows, and the loose gets worse as the run goes on. Too little heats the right front and the push gets worse the same way."),
Tip("Blocks", "Block thickness is rear roll stiffness. More rear roll stiffness tightens the entry and the middle. Over 3 inches cuts forward bite. South Sound allows steel leaves, at least four, with blocks, shackles, and sliders. The tri-state book allows steel or poly leaves and shackles."),
Tip("Sway bar", "The all-thread sets front roll stiffness. Less if the car is tight. More if it is loose. The tri-state book allows a 1-1/4 inch bar in the stock saddles, no heim joints. South Sound's book does not list a bar."),
Tip("Stagger", "Right rear minus left rear, around the center of the tread, with a flexible 1/4-inch tape, at the cold pressure you will race. A tighter radius wants more. More banking wants a little less: about 10 degrees is roughly 1.5% less, and about 20 degrees is roughly 6% less."),
Tip("Locked or open", "On a spool or a welded rear, both tires turn together the whole corner, so stagger steers the middle. An open rear does not. Wenatchee allows an open rear. Stateline is spool or welded. These books do not allow a Detroit Locker. Too much stagger makes the car turn left on the straight. On a bias-ply tire a sliding right rear heats, grows, and the loose gets worse as the run goes on. Too little heats the right front and the push gets worse the same way."),
Tip("Air moves stagger", "On a bias-ply tire, more air on the right, or less on the left, grows the stagger before you change tires. That rear-stagger gain takes cross out. More air that grows the right front adds cross."),
Tip("Toe", "1/16 to 1/8 inch out in front on asphalt. A tighter track wants the larger end. Tracks under a half mile are published out to 1/4 inch. Rear wheels straight. Toe out takes the slack out of the tie-rod ends. Check it after a camber change, a caster change, a ride-height change, or any wheel contact."),
Tip("Added toe", "Toe that grows as the wheel turns is Ackermann. Toe that shrinks is reverse Ackermann. One degree is about 1/2 inch of toe on an 85-inch tire. A tight quarter-mile only needs about 1/16 inch more on the left front. A half-mile needs about 1/64 inch. Stock boxes already add toe in a left turn, so measure it before you add any. Another note calls about 3° of extra left-front steer, in 10° of wheel turn, a common amount, and more of it on a 3/8-mile and under. Past what the corner needs, the left front grains, runs hot, and drags, and the car gets loose off. A little can free a tight middle. You feel it at the apex."),
Tip("String check", "Fronts straight. Mark the floor 10 feet ahead of each spindle. Turn the wheel about as far as the driver does in the corner and mark again. If the left mark moved farther than the right, the car gained toe. If the right mark moved farther, the car lost toe. Tie rods that angle forward from the inner pivot add Ackermann. If the spindle arm is slotted and the book allows it, moving the left tie-rod end closer to the ball joint adds more."),
@@ -270,6 +272,20 @@ private const val OPENING =
"Leaf-spring Camaro on asphalt. Hobby stock or thunder car. If the rule book disagrees, follow the rule book. Change one thing, write it in the log, and read the tires before the next guess."
private val book = listOf(
Chapter(
"How to tell",
"Fix the middle before the entry or the exit. A tight car can feel loose: the driver adds steering, the front bites, and the rear snaps when the throttle comes in. If the wheel is turned farther at speed than on a moderate lap, the car is tight. If it is turned less, it is loose. If you are steering right in the middle, bring it in.",
),
Chapter(
"What to change",
"One change, then another run. Skip a move the rule book does not allow.",
blocksOf(handling),
),
Chapter(
"Air for handling",
"Use this when the only change is air on a bias-ply tire. The same change moves rate, footprint, stagger, and cross. If you only wanted the stagger, put the cross back on the scales. Do not add rear stagger just to free a tight middle.",
blocksOf(airHandling),
),
Chapter(
"Heat",
"Probe inside, middle, outside right after a full-speed run, before the car sits in the stall. Start at the right front, then the right rear, the left rear, and the left front. The right sides cool first. One person probes and one writes. Same order every time. A needle in the tread beats a surface gun. The surface is usually 20–40° cooler than the probe, and brake heat or engine heat can fool the gun. A spread across one tire past about 10% is the one to fix. A new tire runs hotter than a used one, so read camber and pressure from the spread across that tire. Temps on a car that is way off are a weak signal until it is at least drivable.",
@@ -285,26 +301,12 @@ private val book = listOf(
"Write the tire set on the run. Temps, depth, and heat cycles from that set tell you when another week is wishful.",
notesOf(tireLife),
),
Chapter(
"How to tell",
"Fix the middle before the entry or the exit. A tight car can feel loose: the driver adds steering, the front bites, and the rear snaps when the throttle comes in. If the wheel is turned farther at speed than on a moderate lap, the car is tight. If it is turned less, it is loose. If you are steering right in the middle, bring it in.",
),
Chapter(
"What to change",
"One change, then another run. Skip a move the rule book does not allow.",
blocksOf(handling),
),
Chapter(
"Air for handling",
"Longacre's order when the only change is air on a bias-ply tire. The same change moves rate, footprint, stagger, and cross. If you only wanted the stagger, put the cross back on the scales. Size rear stagger for the radius, then leave it. Extra past that gets loose on power, so do not add rear stagger just to free a tight middle.",
blocksOf(airHandling),
),
Chapter("Where to start", blocks = notesOf(starts)),
Chapter(
"Order of work",
"Geometry and alignment come before brakes and aero. On a hobby-stock F-body a lot of the geometry is frozen. Do the items the book allows, in this order, and stop when the car is balanced.",
notesOf(order),
),
Chapter("Where to start", blocks = notesOf(starts)),
Chapter(
"In the shop",
"Do this before the first race, and again when something hits the wall or the car starts doing something new. An alignment with a couple of people is an hour or two.",
@@ -312,7 +314,7 @@ private val book = listOf(
),
Chapter(
"On the scales",
"Write the four corner weights in the notes and the cross on the setup. Same routine every time, or the number does not compare with last week.",
"Write the four corner weights and the cross. Same routine every time, or the number does not compare with last week.",
notesOf(scales),
),
Chapter(
@@ -323,8 +325,25 @@ private val book = listOf(
Chapter("Leave these alone", blocks = notesOf(leaveAlone)),
)
private data class QuickCase(val label: String, val heading: String)
private val quickCases = listOf(
QuickCase("Tight entry", "Entry, tight"),
QuickCase("Loose entry", "Entry, loose"),
QuickCase("Tight middle", "Middle, tight"),
QuickCase("Loose middle", "Middle, loose"),
QuickCase("Tight exit", "Exit, tight"),
QuickCase("Loose exit", "Exit, loose"),
)
private fun holds(words: List<String>, text: String) = words.all { text.contains(it, ignoreCase = true) }
private fun Chapter.forCase(heading: String): Chapter? {
val kept = blocks.filter { it.heading == heading }
if (kept.isEmpty()) return null
return copy(intro = "", blocks = kept)
}
private fun Chapter.narrowed(words: List<String>): Chapter? {
if (holds(words, title)) return this
val introShown = intro.isNotBlank() && holds(words, intro)
@@ -344,12 +363,16 @@ private fun Chapter.narrowed(words: List<String>): Chapter? {
@Composable
fun SetupGuideScreen(onBack: () -> Unit) {
var query by remember { mutableStateOf("") }
var picked by remember { mutableStateOf<QuickCase?>(null) }
val words = query.trim().split(Regex("\\s+")).filter { it.isNotEmpty() }
val shown = if (words.isEmpty()) book else book.mapNotNull { it.narrowed(words) }
val showOpening = words.isEmpty() || holds(words, OPENING)
val shown = when (val choice = picked) {
null -> if (words.isEmpty()) book else book.mapNotNull { it.narrowed(words) }
else -> book.mapNotNull { it.forCase(choice.heading) }
}
val showOpening = picked == null && (words.isEmpty() || holds(words, OPENING))
val scroll = rememberScrollState()
val keyboard = LocalSoftwareKeyboardController.current
LaunchedEffect(query) { scroll.scrollTo(0) }
LaunchedEffect(query, picked) { scroll.scrollTo(0) }
Scaffold(
topBar = {
TopAppBar(
@@ -368,10 +391,20 @@ fun SetupGuideScreen(onBack: () -> Unit) {
.fillMaxSize()
.padding(padding),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Column(
Modifier
.widthIn(max = 640.dp)
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
OutlinedTextField(
value = query,
onValueChange = { query = it },
onValueChange = {
query = it
if (it.isNotEmpty()) picked = null
},
label = { Text("Look up") },
placeholder = { Text("stagger, camber, tight") },
leadingIcon = { Icon(Icons.Filled.Search, contentDescription = null) },
@@ -388,11 +421,28 @@ fun SetupGuideScreen(onBack: () -> Unit) {
imeAction = ImeAction.Search,
),
keyboardActions = KeyboardActions(onSearch = { keyboard?.hide() }),
modifier = Modifier
.widthIn(max = 640.dp)
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
modifier = Modifier.fillMaxWidth(),
)
quickCases.chunked(2).forEach { row ->
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
row.forEach { choice ->
FilterChip(
selected = picked == choice,
onClick = {
picked = if (picked == choice) null else choice
query = ""
keyboard?.hide()
},
label = { Text(choice.label) },
modifier = Modifier.weight(1f),
)
}
}
}
}
Column(
Modifier
.weight(1f)
@@ -455,3 +505,4 @@ private fun TipLine(title: String, body: String) {
Text(body, color = MaterialTheme.colorScheme.onSurface)
}
}
@@ -49,6 +49,7 @@ import com.racingapp.pitlog.model.exportFileName
import com.racingapp.pitlog.model.chassisSetup
import com.racingapp.pitlog.model.chassisTips
import com.racingapp.pitlog.model.formatDegrees
import com.racingapp.pitlog.model.formatInches
import com.racingapp.pitlog.model.formatPsi
import com.racingapp.pitlog.model.formatStagger
import com.racingapp.pitlog.model.handlingText
@@ -237,8 +238,8 @@ private fun SetupBlock(night: RaceNight, latest: RunLog?, onSetup: () -> Unit) {
SetupLine(
"Blocks",
listOf(
night.blockLr?.let { "LR ${String.format(java.util.Locale.US, "%.1f", it)} in" },
night.blockRr?.let { "RR ${String.format(java.util.Locale.US, "%.1f", it)} in" },
night.blockLr?.let { "LR ${formatInches(it)} in" },
night.blockRr?.let { "RR ${formatInches(it)} in" },
).filterNotNull().joinToString(" ").ifBlank { null },
)
SetupLine(
@@ -31,9 +31,12 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.racingapp.pitlog.data.RaceNight
import com.racingapp.pitlog.data.Repository
import com.racingapp.pitlog.model.formatInches
import com.racingapp.pitlog.model.parseDecimal
import com.racingapp.pitlog.model.parseInches
import com.racingapp.pitlog.model.parseIntField
import com.racingapp.pitlog.model.sanitizeDecimal
import com.racingapp.pitlog.model.sanitizeInches
import com.racingapp.pitlog.model.sanitizeInt
import com.racingapp.pitlog.model.sanitizeSignedDecimal
import com.racingapp.pitlog.ui.FieldRow
@@ -71,8 +74,8 @@ private data class SetupForm(
casterLf = parseDecimal(casterLf),
casterRf = parseDecimal(casterRf),
swayBarHole = parseIntField(swayBarHole),
blockLr = parseDecimal(blockLr),
blockRr = parseDecimal(blockRr),
blockLr = parseInches(blockLr),
blockRr = parseInches(blockRr),
)
companion object {
@@ -87,8 +90,8 @@ private data class SetupForm(
casterLf = signedField(night.casterLf),
casterRf = signedField(night.casterRf),
swayBarHole = night.swayBarHole?.toString().orEmpty(),
blockLr = night.blockLr?.let { String.format(Locale.US, "%.1f", it) }.orEmpty(),
blockRr = night.blockRr?.let { String.format(Locale.US, "%.1f", it) }.orEmpty(),
blockLr = formatInches(night.blockLr),
blockRr = formatInches(night.blockRr),
)
}
}
@@ -246,7 +249,7 @@ fun SetupEditorScreen(nightId: Long, onBack: () -> Unit) {
}
SectionLabel("Blocks, inches")
Text(
"Under the leaves. More block tightens entry and the middle. Over 3 inches cuts forward bite. String the rear after you move them.",
"Block thickness is rear roll stiffness. More rear roll stiffness tightens entry and the middle. Over 3 inches cuts forward bite. String the rear after you move them.",
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
FieldRow {
@@ -254,22 +257,26 @@ fun SetupEditorScreen(nightId: Long, onBack: () -> Unit) {
label = "LR",
value = form.blockLr,
onValue = { value ->
viewModel.update { it.copy(blockLr = sanitizeDecimal(value, 1, 1)) }
viewModel.update { it.copy(blockLr = sanitizeInches(value)) }
},
inches = true,
placeholder = "1/2",
modifier = Modifier.weight(1f),
)
NumberField(
label = "RR",
value = form.blockRr,
onValue = { value ->
viewModel.update { it.copy(blockRr = sanitizeDecimal(value, 1, 1)) }
viewModel.update { it.copy(blockRr = sanitizeInches(value)) }
},
inches = true,
placeholder = "1/2",
modifier = Modifier.weight(1f),
)
}
SectionLabel("Sway bar")
Text(
"Where the bar is now. Less bar if the car is tight. More bar if it is loose. The bar has to move freely: space the mounts off the frame, or use a bushing about 1/8 inch larger than the bar.",
"The all-thread sets front roll stiffness. Less if the car is tight. More if it is loose. The bar has to move freely: space the mounts off the frame, or use a bushing about 1/8 inch larger than the bar.",
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
NumberField(
@@ -52,6 +52,7 @@ import com.racingapp.pitlog.model.Tread
import com.racingapp.pitlog.model.formatPsi
import com.racingapp.pitlog.model.hasColdPressure
import com.racingapp.pitlog.model.sanitizeDecimal
import com.racingapp.pitlog.model.sanitizeInches
import com.racingapp.pitlog.model.sanitizeInt
import com.racingapp.pitlog.model.suspiciousReadings
import com.racingapp.pitlog.model.toSheet
@@ -261,8 +262,10 @@ fun RunEditorScreen(
label = "Stagger",
value = form.stagger,
onValue = { value ->
viewModel.update { it.copy(stagger = sanitizeDecimal(value, 2, 2)) }
viewModel.update { it.copy(stagger = sanitizeInches(value)) }
},
inches = true,
placeholder = "1/8",
modifier = Modifier.weight(1f),
)
}
@@ -32,13 +32,16 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.racingapp.pitlog.data.Repository
import com.racingapp.pitlog.data.SetupSheet
import com.racingapp.pitlog.model.formatInches
import com.racingapp.pitlog.model.parseDecimal
import com.racingapp.pitlog.model.parseInches
import com.racingapp.pitlog.model.parseIntField
import com.racingapp.pitlog.model.sanitizeDecimal
import com.racingapp.pitlog.model.sanitizeInches
import com.racingapp.pitlog.model.sanitizeInt
import com.racingapp.pitlog.model.sanitizeSignedDecimal
import com.racingapp.pitlog.model.scaleLines
import com.racingapp.pitlog.model.setupDiffs
import com.racingapp.pitlog.model.weightSplit
import com.racingapp.pitlog.ui.FieldRow
import com.racingapp.pitlog.ui.NumberField
import com.racingapp.pitlog.ui.PitActionButton
@@ -88,15 +91,15 @@ private data class CarSetupForm(
casterLf = parseDecimal(casterLf),
casterRf = parseDecimal(casterRf),
swayBarHole = parseIntField(swayBarHole),
blockLr = parseDecimal(blockLr),
blockRr = parseDecimal(blockRr),
toeFront = parseDecimal(toeFront),
toeRear = parseDecimal(toeRear),
blockLr = parseInches(blockLr),
blockRr = parseInches(blockRr),
toeFront = parseInches(toeFront),
toeRear = parseInches(toeRear),
weightLf = parseIntField(weightLf),
weightRf = parseIntField(weightRf),
weightLr = parseIntField(weightLr),
weightRr = parseIntField(weightRr),
rideHeight = parseDecimal(rideHeight),
rideHeight = parseInches(rideHeight),
pinion = parseDecimal(pinion),
brakeFront = parseDecimal(brakeFront),
)
@@ -113,15 +116,15 @@ private data class CarSetupForm(
casterLf = decimal(sheet.casterLf, 1),
casterRf = decimal(sheet.casterRf, 1),
swayBarHole = sheet.swayBarHole?.toString().orEmpty(),
blockLr = decimal(sheet.blockLr, 1),
blockRr = decimal(sheet.blockRr, 1),
toeFront = decimal(sheet.toeFront, 3),
toeRear = decimal(sheet.toeRear, 3),
blockLr = formatInches(sheet.blockLr),
blockRr = formatInches(sheet.blockRr),
toeFront = formatInches(sheet.toeFront),
toeRear = formatInches(sheet.toeRear),
weightLf = sheet.weightLf?.toString().orEmpty(),
weightRf = sheet.weightRf?.toString().orEmpty(),
weightLr = sheet.weightLr?.toString().orEmpty(),
weightRr = sheet.weightRr?.toString().orEmpty(),
rideHeight = decimal(sheet.rideHeight, 1),
rideHeight = formatInches(sheet.rideHeight),
pinion = decimal(sheet.pinion, 1),
brakeFront = decimal(sheet.brakeFront, 1),
note = if (keepNote) sheet.note else "",
@@ -320,13 +323,17 @@ fun CarSetupEditorScreen(
NumberField(
label = "LR",
value = form.blockLr,
onValue = { value -> viewModel.update { it.copy(blockLr = sanitizeDecimal(value, 1, 1)) } },
onValue = { value -> viewModel.update { it.copy(blockLr = sanitizeInches(value)) } },
inches = true,
placeholder = "1/2",
modifier = Modifier.weight(1f),
)
NumberField(
label = "RR",
value = form.blockRr,
onValue = { value -> viewModel.update { it.copy(blockRr = sanitizeDecimal(value, 1, 1)) } },
onValue = { value -> viewModel.update { it.copy(blockRr = sanitizeInches(value)) } },
inches = true,
placeholder = "1/2",
modifier = Modifier.weight(1f),
)
}
@@ -354,12 +361,12 @@ fun CarSetupEditorScreen(
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
FieldRow {
SignedField("Front", form.toeFront, { value -> viewModel.update { it.copy(toeFront = value) } }, Modifier.weight(1f), 1, 3)
SignedField("Rear", form.toeRear, { value -> viewModel.update { it.copy(toeRear = value) } }, Modifier.weight(1f), 1, 3)
SignedField("Front", form.toeFront, { value -> viewModel.update { it.copy(toeFront = value) } }, Modifier.weight(1f), inches = true)
SignedField("Rear", form.toeRear, { value -> viewModel.update { it.copy(toeRear = value) } }, Modifier.weight(1f), inches = true)
}
SectionLabel("Corner weights, lb")
Text(
"Pounds on the pads. Left, rear, and cross are figured from these four.",
"Pounds on the pads. Left, front, rear, and cross come out in pounds and percent. Rear bite is left rear minus right rear.",
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
FieldRow {
@@ -394,13 +401,13 @@ fun CarSetupEditorScreen(
modifier = Modifier.weight(1f),
)
}
weightSplit(
scaleLines(
form.weightLf.toIntOrNull(),
form.weightRf.toIntOrNull(),
form.weightLr.toIntOrNull(),
form.weightRr.toIntOrNull(),
)?.let { split ->
Text(split, modifier = Modifier.padding(top = 8.dp))
).forEach { line ->
Text(line, modifier = Modifier.padding(top = 8.dp))
}
SectionLabel("Ride height")
Text(
@@ -410,7 +417,9 @@ fun CarSetupEditorScreen(
NumberField(
label = "Inches",
value = form.rideHeight,
onValue = { value -> viewModel.update { it.copy(rideHeight = sanitizeDecimal(value, 2, 1)) } },
onValue = { value -> viewModel.update { it.copy(rideHeight = sanitizeInches(value)) } },
inches = true,
placeholder = "5",
modifier = Modifier.fillMaxWidth(),
)
SectionLabel("Pinion")
@@ -457,6 +466,7 @@ private fun SignedField(
value: String,
onValue: (String) -> Unit,
modifier: Modifier = Modifier,
inches: Boolean = false,
wholeDigits: Int = 2,
fractionDigits: Int = 1,
) {
@@ -464,7 +474,14 @@ private fun SignedField(
NumberField(
label = label,
value = value,
onValue = { onValue(sanitizeSignedDecimal(it, wholeDigits, fractionDigits)) },
onValue = {
onValue(
if (inches) sanitizeInches(it, signed = true)
else sanitizeSignedDecimal(it, wholeDigits, fractionDigits),
)
},
inches = inches,
placeholder = if (inches) "1/16" else "",
modifier = Modifier.fillMaxWidth(),
)
TextButton(
@@ -0,0 +1,31 @@
package com.racingapp.pitlog.model
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class InchesTest {
@Test
fun aFractionParsesAndComesBackAsAFraction() {
assertEquals(0.0625, parseInches("1/16")!!, 0.00001)
assertEquals(0.125, parseInches("1/8")!!, 0.00001)
assertEquals(2.5, parseInches("2 1/2")!!, 0.00001)
assertEquals(-0.0625, parseInches("-1/16")!!, 0.00001)
assertEquals(1.125, parseInches("1.125")!!, 0.00001)
assertEquals("1/16", formatInches(parseInches("1/16")))
assertEquals("1/8", formatInches(parseInches("1/8")))
assertEquals("2 1/2", formatInches(parseInches("2 1/2")))
assertEquals("-1/16", formatInches(parseInches("-1/16")))
assertEquals("1 1/8", formatInches(1.125))
}
@Test
fun typingKeepsTheSlashUntilTheFractionIsFinished() {
assertEquals("1/16", sanitizeInches("1/16"))
assertEquals("1/", sanitizeInches("1/"))
assertEquals("2 1/2", sanitizeInches("2 1/2"))
assertEquals("-1/8", sanitizeInches("-1/8", signed = true))
assertNull(parseInches("1/"))
assertNull(parseInches("1/0"))
}
}
@@ -23,7 +23,7 @@ class SetupLogTest {
listOf(
"RF spring 1000 lb → 1050 lb",
"Sway bar Setting 4 → Setting 3",
"Front toe 0.125 in → 0.063 in",
"Front toe 1/8 in → 1/16 in",
),
setupDiffs(original, later),
)
@@ -56,7 +56,12 @@ class SetupLogTest {
assertEquals(
listOf(
"Weights LF 800 RF 760 LR 740 RR 700 lb",
"From the weights Left 51.3% Rear 48% Cross 50%",
"Total 3000 lb",
"Left 1540 lb, 51.3%",
"Front 1560 lb, 52%",
"Rear 1440 lb, 48%",
"Cross 1500 lb, 50%",
"Rear bite 40",
"Ride height 5 in",
"Pinion -2.0°",
"Front brake 62%",
@@ -66,6 +71,11 @@ class SetupLogTest {
assertEquals(
listOf(
"LF weight 800 lb → 820 lb",
"Total 3000 lb → 3020 lb",
"Left 1540 lb, 51.3% → 1560 lb, 51.7%",
"Front 1560 lb, 52% → 1580 lb, 52.3%",
"Rear 1440 lb, 48% → 1440 lb, 47.7%",
"Cross 1500 lb, 50% → 1500 lb, 49.7%",
"Ride height 5 in → 5.2 in",
"Pinion -2.0° → -1.5°",
"Front brake 62% → 65%",
@@ -116,9 +116,9 @@ class TireSheetTest {
assertTrue(softRear.single().say.contains("softer right rear"))
val tightBar = chassisTips(ChassisSetup(swayBarHole = 4), handling = "Tight")
assertEquals("Less bar.", tightBar.single().say)
assertEquals("Less front roll stiffness.", tightBar.single().say)
val looseBar = chassisTips(ChassisSetup(swayBarHole = 4), handling = "Loose")
assertEquals("More bar.", looseBar.single().say)
assertEquals("More front roll stiffness.", looseBar.single().say)
assertTrue(chassisTips(ChassisSetup(swayBarHole = 4)).isEmpty())
val tightBlocks = chassisTips(
@@ -126,13 +126,13 @@ class TireSheetTest {
handling = "Tight",
handlingWhere = "Entry",
)
assertEquals("Less block.", tightBlocks.single().say)
assertEquals("Less rear roll stiffness.", tightBlocks.single().say)
val looseBlocks = chassisTips(
ChassisSetup(blockLr = 2.0, blockRr = 2.0),
handling = "Loose",
handlingWhere = "Center",
)
assertEquals("More block.", looseBlocks.single().say)
assertEquals("More rear roll stiffness.", looseBlocks.single().say)
assertTrue(
chassisTips(
ChassisSetup(blockLr = 2.0, blockRr = 2.0),
+5
View File
@@ -451,7 +451,12 @@ def serve():
print(f"Pit Log sync listening on {port}", flush=True)
print("Each car in the app has its own token.", flush=True)
server = ThreadingHTTPServer(("0.0.0.0", port), Handler)
try:
server.serve_forever()
except KeyboardInterrupt:
print("Pit Log sync stopped.", flush=True)
finally:
server.server_close()
def selftest():