Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiqian committed Aug 11, 2023
1 parent 4997572 commit b901534
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,6 @@ open class KChart(
mapPointsReal2Value(tmp4FloatArray)
val leftIdx = (tmp4FloatArray[0] + 0.5f).toInt()
val rightIdx = (tmp4FloatArray[2] + 0.5f).toInt() - 1
getKEntities().filterIndexed { kEntityIdx, kEntity ->
kEntityIdx in leftIdx..rightIdx && !kEntity.containFlag(
FLAG_EMPTY
)
}
.map { it.getHighPrice() }.max()

var maxIdx: Int? = null
var minIdx: Int? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@ import kotlin.math.sqrt
* @author wangyiqian E-mail: [email protected]
* @version 创建时间: 2021/2/16
*/
object BollCalculator: ICalculator {
object BollCalculator : ICalculator {

override fun calculate(param: String, input: List<IKEntity>): List<List<Float?>> {
val paramList = param.split(",")
val n = paramList[0].toInt()
val k = paramList[1].toInt()
val n = try {
paramList[0].toInt()
} catch (tr: Throwable) {
null
}
val k = try {
paramList[1].toInt()
} catch (tr: Throwable) {
null
}

if (n == null || k == null) {
return emptyList()
}

// 1. MB 2.UP 3.DN
val result = MutableList(3) { MutableList<Float?>(input.size) { 0f } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ object EMACalculator : ICalculator {

override fun calculate(param: String, input: List<IKEntity>): List<List<Float?>> {
val paramList = param.split(",")
val emaPeriodList = paramList.map { it.toInt() }
val emaPeriodList = try {
paramList.map { it.toInt() }
} catch (tr: Throwable) {
emptyList<Int>()
}

val result = MutableList(emaPeriodList.size) { MutableList<Float?>(input.size) { 0f } }
input.forEachIndexed { kEntityIdx, kEntity ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@ import kotlin.math.min
* @author wangyiqian E-mail: [email protected]
* @version 创建时间: 2021/2/18
*/
object KDJCalculator: ICalculator {
object KDJCalculator : ICalculator {

override fun calculate(param: String, input: List<IKEntity>): List<List<Float?>> {
val paramList = param.split(",")
val n = paramList[0].toInt()
val kn = paramList[1].toInt()
val dn = paramList[2].toInt()
val n = try {
paramList[0].toInt()
} catch (tr: Throwable) {
null
}
val kn = try {
paramList[1].toInt()
} catch (tr: Throwable) {
null
}
val dn = try {
paramList[2].toInt()
} catch (tr: Throwable) {
null
}

if (n == null || kn == null || dn == null) {
return emptyList()
}

val result = MutableList(3) { MutableList<Float?>(input.size) { 0f } }
val kIdx = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,24 @@ object MACDCalculator : ICalculator {

override fun calculate(param: String, input: List<IKEntity>): List<List<Float?>> {
val paramList = param.split(",")
val shortPeriod = paramList[0].toInt()
val longPeriod = paramList[1].toInt()
val avgPeriod = paramList[2].toInt()
val shortPeriod = try {
paramList[0].toInt()
} catch (tr: Throwable) {
null
}
val longPeriod = try {
paramList[1].toInt()
} catch (tr: Throwable) {
null
}
val avgPeriod = try {
paramList[2].toInt()
} catch (tr: Throwable) {
null
}
if (shortPeriod == null || longPeriod == null || avgPeriod == null) {
return emptyList()
}

val result = MutableList(3) { MutableList<Float?>(input.size) { 0f } }
val difIdx = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ import com.github.wangyiqian.stockchart.entities.containFlag
* @author wangyiqian E-mail: [email protected]
* @version 创建时间: 2021/2/14
*/
object MACalculator: ICalculator {
object MACalculator : ICalculator {

override fun calculate(param: String, input: List<IKEntity>): List<List<Float?>> {
val paramList = param.split(",")
val periodList = paramList.map { it.toInt() }
val periodList = try {
paramList.map { it.toInt() }
} catch (tr: Throwable) {
emptyList<Int>()
}

val result = MutableList(periodList.size) { MutableList<Float?>(input.size) { 0f } }
val pFromList = MutableList(periodList.size) { 0 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import kotlin.math.min
object RSICalculator : ICalculator {
override fun calculate(param: String, input: List<IKEntity>): List<List<Float?>> {
val paramList = param.split(",")
val periodList = paramList.map { it.toInt() }
val periodList = try {
paramList.map { it.toInt() }
} catch (tr: Throwable) {
emptyList<Int>()
}
val result = MutableList(periodList.size) { MutableList<Float?>(input.size) { 0f } }
val preAvgRiseList = MutableList(periodList.size) { 0f }
val preAvgDownList = MutableList(periodList.size) { 0f }
Expand Down

0 comments on commit b901534

Please sign in to comment.